警告:“UIViewController”可能无法响应“xxx”
我对 iPhone 开发还比较陌生,但我知道这个警告通常是由于我的类头文件中没有声明方法而导致的。这略有不同——至少我认为是这样。
我在我的应用程序根视图控制器中创建了一个自定义选项卡栏,它在委托方法内动态加载其他视图控制器 - 本质上是这样的:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
UIViewController *viewController = [viewControllers objectAtIndex:item.tag];
[self.selectedViewController.view removeFromSuperview];
[self.view insertSubview:viewController.view atIndex:0];
self.selectedViewController = viewController;
}
该代码工作正常并加载到所需的视图中。当视图更改时,将运行检查以查看设置视图是否即将被卸载,如果是,则调用保存设置方法,如下所示:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if (self.currentController == 1) {
[self.selectedViewController saveSettings];
}
UIViewController *viewController = [viewControllers objectAtIndex:item.tag];
[self.selectedViewController.view removeFromSuperview];
[self.view insertSubview:viewController.view atIndex:0];
self.selectedViewController = viewController;
}
代码再次运行良好,并且调用了 SettingsViewController 的实例方法,但是因为该方法位于 SettingsViewController 的标头中,而不是 RootViewController 中,因此会出现警告。
如果我也在 RootViewController 中声明它,我会收到“无匹配方法声明”警告。我认为重新声明我的函数可以解决该警告 - 但肯定不是解决此问题的“正确”方法。
I'm still relatively new to iPhone development but I know this warning is usually the result of not declaring a method in my classes header file. This is slightly different - at least I think it is.
I've created a custom tab bar in my applications root view controller which loads in the other view controllers dynamically inside the delegate method - essentially like this:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
UIViewController *viewController = [viewControllers objectAtIndex:item.tag];
[self.selectedViewController.view removeFromSuperview];
[self.view insertSubview:viewController.view atIndex:0];
self.selectedViewController = viewController;
}
That code works fine and loads in the required views. When the view changes a check is run to see if the setting view is about to be unloaded and if so it calls the save settings method like this:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if (self.currentController == 1) {
[self.selectedViewController saveSettings];
}
UIViewController *viewController = [viewControllers objectAtIndex:item.tag];
[self.selectedViewController.view removeFromSuperview];
[self.view insertSubview:viewController.view atIndex:0];
self.selectedViewController = viewController;
}
Again the code functions fine and the instance method of SettingsViewController is called, but because the declaration of the method is in the header of the SettingsViewController and not the RootViewController hence the warning.
If I declare it in the RootViewController as well I get the 'no matching method declaration' warning. I presume redeclaring my function would fix the warning - but surely isn't the 'proper' way to fix this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题,这应该有效:
If I understand your question correctly, this should work: