Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c iOS:处理didSelectViewController时出现警告_Objective C_Ios - Fatal编程技术网

Objective c iOS:处理didSelectViewController时出现警告

Objective c iOS:处理didSelectViewController时出现警告,objective-c,ios,Objective C,Ios,以下代码: - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { if (viewController == [tabBarController.viewControllers objectAtIndex:0]) { MySearchViewController *control

以下代码:

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

只需更改以下内容:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    if (viewController == [tabBarController.viewControllers objectAtIndex:0] && [viewController isKindOfClass:[MySearchViewController class]]) {
        MySearchViewController *controller = (MySearchViewController *)viewController;
        [[controller tableView] reloadData];
    }
}

您是否只是尝试了
MySearchViewController*控制器=(MySearchViewController*)视图控制器?嘿,太好了。那是。。。在Objective C中进行适当的强制转换?它只是告诉编译器您知道它属于那种类型,所以它不会显示警告。它对对象没有任何作用。因此,如果viewController是另一种类型的类,它将崩溃。