CYLTabBarController icon indicating copy to clipboard operation
CYLTabBarController copied to clipboard

[bug]:初始化崩溃。。。

Open DuShuYuan opened this issue 3 years ago • 2 comments

版本:1.29.0 代码:

let mainVc = MainView(viewControllers: [
            UINavigationController(rootViewController: BookshelfView()),
            UINavigationController(rootViewController: BookStoreView()),
            UINavigationController(rootViewController: PersonalView())
        ], tabBarItemsAttributes: [
            [CYLTabBarItemTitle: "书架",
             CYLTabBarItemImage: R.image.tab_bookshelf_normal.name,
             CYLTabBarItemSelectedImage: R.image.tab_bookshelf_selected.name],
            [CYLTabBarItemTitle: "书城",
             CYLTabBarItemImage: R.image.tab_store_normal.name,
             CYLTabBarItemSelectedImage: R.image.tab_store_selected.name],
            [CYLTabBarItemTitle: "我的",
             CYLTabBarItemImage: R.image.tab_personal_normal.name,
             CYLTabBarItemSelectedImage: R.image.tab_personal_selected.name]
        ])
        navigationController?.pushViewController(mainVc, animated: true)

崩溃日志

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UITabBar 0x7f7f0f5126e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key context.'
CoreSimulator 732.18.6 - Device: iPhone 11 (B0F46405-006B-4769-BFB1-8527CFCB0D75) - Runtime: iOS 14.4 (18D46) - DeviceType: iPhone 11
terminating with uncaught exception of type NSException

崩溃代码位置


- (instancetype)initWithViewControllers:(NSArray<UIViewController *> *)viewControllers
                  tabBarItemsAttributes:(NSArray<NSDictionary *> *)tabBarItemsAttributes
                            imageInsets:(UIEdgeInsets)imageInsets
                titlePositionAdjustment:(UIOffset)titlePositionAdjustment
                                context:(NSString *)context {
    if (self = [super init]) {
        
        _imageInsets = imageInsets;
        _titlePositionAdjustment = titlePositionAdjustment;
        _tabBarItemsAttributes = tabBarItemsAttributes;
        self.context = context;//这里
        self.viewControllers = viewControllers;
    }
    return self;
}

- (void)setContext:(NSString *)context {
    if (context && context.length > 0) {
        _context = [context copy];
    } else {
        _context = NSStringFromClass([CYLTabBarController class]);
    }
    [self.tabBar setValue:_context forKey:@"context"]; //这里
}

DuShuYuan avatar Mar 29 '21 03:03 DuShuYuan

我也遇到了... 求解决

mybkin2019 avatar Aug 03 '21 16:08 mybkin2019

MainView 是不是少了 super.viewDidLoad()

lucky5237 avatar Feb 28 '22 08:02 lucky5237