RJBadgeKit icon indicating copy to clipboard operation
RJBadgeKit copied to clipboard

dispatch_queue_async_rjbk went wrong in viewDidLoad

Open zljkevin opened this issue 6 years ago • 1 comments

In application: didFinishLaunchingWithOptions:

 UITabBarController *tabVC = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    UITabBarItem *mineItem = tabVC.tabBar.items.lastObject;
    NSString *minePath = @"root.mine";
    
    mineItem.badgeOffset = CGPointMake(5, 5);
    
    [self.badgeController observePath:minePath badgeView:mineItem block:^(id _Nullable observer, NSDictionary<NSString *,id> * _Nonnull info) {
        NSLog(@"%@",info);
    }];
    
    NSString *mineMessagePath = @"root.mine.message";
    
    [RJBadgeController setBadgeForKeyPath:mineMessagePath count:9];

In MineViewController viewDidLoad

    NSString *mineMessagePath = @"root.mine.message";
    [self.badgeController observePath:mineMessagePath badgeView:self.navigationItem.leftBarButtonItem block:^(id _Nullable observer, NSDictionary<NSString *,id> * _Nonnull info) {
        NSLog(@"%@",info);
    }];

leftBarButtonItem in MineViewController did not show the badge, caused by dispatch_queue_async_rjbk did not execute the code!

Use

dispatch_async(dispatch_get_main_queue(), ^{
});

instead.

zljkevin avatar Jun 01 '18 08:06 zljkevin

iOS 11.3.1, Xcode9.4 ,iPhone8

zljkevin avatar Jun 01 '18 08:06 zljkevin