iOS: More tab crashes on my subclassed UITabBarController on iOS 7.1

北慕城南 提交于 2019-12-18 17:04:09

问题


I simply updated to iOS 7.1 and I get an unrecognized selection error for a function called "_layoutCells".

I have a simple subclass of UITabBarController.


回答1:


Note that this is a hack to avoid a bad crash until a better solution or explanation is found. I though I should share it.

Simply add the following method to your UITabBarController subclass implementation:

- (void) _layoutCells
{
    // HACK ALERT: on iOS 7.1, this method will be called from deep within the bowels of iOS.  The problem is that
    // the method is not implemented and it results in an unrecognized selected crash. So we implement it...
    //
    // What could go wrong?
}



回答2:


Thanks to GenesisST for giving his answer, but I know methods are called for a reason. And usually layoutCells will call layout for all subviews. While I rather wait for an answer from Apple, I like other people need to submit my app within a given timeline.

In my case, I was getting this error due to some hacks. I had replaced the UIMoreNavigationController delegate, which is an undocumented class by Apple, so I could expect errors. I am doing this hack to extend the More tab's functionality, and this error only occurs when I change the moreNavigationController tableView's delegate.

So I store their delegate, change it, then call _layoutCells to their delegate when iOS calls it on my class.

- (void)_layoutCells
{
   if([self.moreTableViewDelegate respondsToSelector:@selector(_layoutCells)]){
      [self.moreTableViewDelegate performSelector:@selector(_layoutCells)];
   }
}

I don't know if this apply's to anyone here, but just in case someone else comes to SO with my edge case.




回答3:


I've had the same issue in my app where I have provided custom delegate/datasource to the more tableview controller. I haven't figured out why, but it seems that _layoutCells method is invoked on the more tableview controller. I fixed it, adding this method:

-(NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
    // self.viewController is my tabBarController
    UINavigationController* moreNavigationController = self.viewController.moreNavigationController; 

    // Retrieve the more list controller (it is the first in the hierarchy)
    id moreListController = moreNavigationController.viewControllers.firstObject;

    Class moreTableViewClass = [moreListController class];
    if (moreTableViewClass) {
        return [moreTableViewClass instanceMethodSignatureForSelector:aSelector];
    }

    return nil;
}

I've done various test and it seems a reliable workaround. But if you'll find better solution... share it!



来源:https://stackoverflow.com/questions/22309289/ios-more-tab-crashes-on-my-subclassed-uitabbarcontroller-on-ios-7-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!