gpt4 book ai didi

objective-c - iOS:处理 didSelectViewController 时的警告

转载 作者:行者123 更新时间:2023-11-28 22:50:24 25 4
gpt4 key购买 nike

以下代码:

- (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];
}
}

关于objective-c - iOS:处理 didSelectViewController 时的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12125396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com