ChenYilong / CYLTabBarController

[EN]It is an iOS UI module library for adding animation to iOS tabbar items and icons with Lottie, and adding a bigger center UITabBar Item. [CN]【中国特色 TabBar】一行代码实现 Lottie 动画TabBar,支持中间带+号的TabBar样式,自带红点角标,支持动态刷新。【iOS13 & Dark Mode & iPhone XS MAX supported】
MIT License
6.91k stars 1.45k forks source link

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

Open DuShuYuan opened 3 years ago

DuShuYuan commented 3 years ago

版本: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"]; //这里
}
mybkin2019 commented 3 years ago

我也遇到了... 求解决

lucky5237 commented 2 years ago

MainView 是不是少了 super.viewDidLoad()