开发者

Analyzer warning: "Incorrect decrement of the reference count" for UITabBarController

Description:

Let's say I've got a class that contains UITabBarController and a bunch of controllers.

Now, one of the controllers (specialController) is not allowed to be selected by UITabBarController. I show him in different way (but I still want to have him in UITabBarController's viewControllers)

By disallowing specialController to be selected, I'm missing init done by UITabBarController. That's why I call init on it by hand.

The problem:

When I run "Build and Analyzie", I receive warning

Incorrect decrement of the reference count of an object that is not owned at this point by the caller

in the line with myinit. But, the application works. What am I missing?

Code:

in the ClassA.m

//called in viewDidLoad
- (void)makeVoodooOnViewControllers {
    //set all variable开发者_JAVA技巧s etc.
    for (int i = 0; i<controllersCount; i++) {
      UIViewController *tabViewController = [tabBarController.viewControllers
                                                             objectAtIndex:i];
     //CUT - some irrelevant code

     if ([tabViewController isKindOfClass:[specialController class]]) {
       //line below throws a warning
       specialControllerProperty = [((specialController *)tabViewController) init];
     }
}

If I'm not clear, please let me know :). Thanks!


How do the view controllers get into the tabBarController.viewControllers array?

If they are setup in the xib file then init is called as part of reanimating them from the xib and should not be called again. It's almost never the case that you want to call init anywhere except directly after you call alloc. Having an alloc'd but unitialized object hanging around seems like a very (very!) rare and unlikely to be desirable situation....

Fundamentally, having a controller in the tab controller controllers list that isn't part of the tab controller controlled controllers seems like a bad design idea - counter the the expectations and design of the tab controller class... and thus likely to cause problems.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜