0
下面的代碼時:的iOS:警告處理didSelectViewController
- (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
調用它的方法的正確方法?
你簡單地嘗試'MySearchViewController *控制器=(MySearchViewController *)的viewController;'? – DrummerB
嘿,那太好了。目標C中是否正確鑄造? – Wells
它只是告訴編譯器,你知道它是那種類型的,所以它不顯示警告。它不會對對象做任何事情。所以如果viewController變成另一種類型,它會崩潰。 – DrummerB