以下代码:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (viewController == [tabBarController.viewControllers objectAtIndex:0]) {
MySearchViewController *controller = viewController;
[[controller tableView] reloadData];
}
}
产生以下警告:
Incompatible pointer types initializing 'MySearchViewController *__strong' with an expression of type 'UIViewController *__strong'
将viewController
投射到适当的班级MySearchViewController
以调用其方法的正确方法是什么?
答案 0 :(得分:2)
改为:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (viewController == [tabBarController.viewControllers objectAtIndex:0] && [viewController isKindOfClass:[MySearchViewController class]]) {
MySearchViewController *controller = (MySearchViewController *)viewController;
[[controller tableView] reloadData];
}
}