當tableView.scrollsToTop=YES不管用時,可以使用以下方法實現點擊狀態欄使tableView滾動到頂部。
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; CGPoint location = [[[event allTouches] anyObject] locationInView:self.view]; CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; if (CGRectContainsPoint(statusBarFrame, location)) { [UIView animateWithDuration:0.3f animations:^{ self.tableView.contentOffset = CGPointMake(0, self.tableViewOriginalOffset); [self.tableView layoutIfNeeded]; }]; } }
參考地址:http://stackoverflow.com/questions/3753097/how-to-detect-touches-in-status-bar