cwRichardKim / RKNotificationHub

Make any UIView a full fledged notification center
MIT License
3.04k stars 327 forks source link

[barButtonItem valueForKey:@"view"] returns nil #26

Open jonnyro23 opened 8 years ago

jonnyro23 commented 8 years ago

[barButtonItem valueForKey:@"view"]

sometimes returns nil and hub not showing up

huangboju commented 8 years ago

view -> _view have a try

cwRichardKim commented 8 years ago

what is the intended use case here? (apologies for late response)

marcuswu0814 commented 8 years ago

@cwRichardKim , when using UIBarButtonItem's init method initWithTitle:style:target:action: will cause this issue, if create a UIBarButtonItem with customView, it work well.

cwRichardKim commented 8 years ago

not sure i understand, but can i close this issue?

Lasithih commented 7 years ago

Have the same problem

jkpang commented 7 years ago

iOS Custom Badge, Support UIView, UITabBarItem, UIBarButtonItem ,Support Objective-C/Swift : https://github.com/jkpang/PPBadgeView have a try

hanks-hu commented 6 years ago

You can use dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.001 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ self.rightBarButtonHub = [[RKNotificationHub alloc] initWithBarButtonItem: BarButtonItemm]; });

allaire commented 6 years ago

Fixed the issue by switching to customView UIBarButtonItem:

Before:

    var activityViewsBarButtonItem: UIBarButtonItem {
        return UIBarButtonItem(image: UIImage(named: "AlarmIcon"), style: .plain, target: self, action: #selector(BaseTabBarController.activityViewsBarButtonItemPressed(_:)))
    }

After:

    var activityViewsBarButtonItem: UIBarButtonItem {
        let button = UIButton(type: .system)
        button.setImage(UIImage(named: "AlarmIcon"), for: .normal)
        button.frame = CGRect(x: 0, y: 0, width: 35, height: 35)
        button.addTarget(self, action: #selector(BaseTabBarController.activityViewsBarButtonItemPressed(_:)), for: .touchUpInside)

        return UIBarButtonItem(customView: button)
    }

And then it worked. I think this was a regression in iOS 11 (unsure). @cwRichardKim hope it helps!