iOS:处理didSelectViewController时出现警告

时间:2012-08-25 20:29:11

标签: objective-c ios

以下代码:

- (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以调用其方法的正确方法是什么?

1 个答案:

答案 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];
    }
}