开发者

warning: 'UIViewController' may not respond to 'xxx'

开发者 https://www.devze.com 2023-03-03 18:47 出处:网络
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'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.selectedViewC开发者_如何学Controller = 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.


If I understand your question correctly, this should work:

if (self.currentController == 1) {
    [(SettingsViewController *)self.selectedViewController saveSettings];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号