タブバーがクリックされたときにテーブルビューの一番上までスクロールするソリューションは次のとおりです
AppDelegateでタブバーデリゲートを設定します
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (tabBarController.selectedIndex == 0) {
UINavigationController *selectedNav = [self.tabBarController.viewControllers objectAtIndex:self.tabBarController.selectedIndex];
UIViewController *currentVC = selectedNav.visibleViewController;
if([currentVC isMemberOfClass:NSClassFromString(@"HomeViewController")])
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshView" object:nil];
}
}
return YES;
}
HomeViewController.mで、ビューは通知をリッスンしました
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(refreshView:)
name:@"refreshView"
object:nil];
リフレッシュ方法
-(void)refreshView:(NSNotification *) notification{
if (self == self.navigationController.topViewController)
[self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
}