Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jonnyro23 opened this issue Jul 19, 2016 · 8 comments
Open

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

jonnyro23 opened this issue Jul 19, 2016 · 8 comments

Comments

@jonnyro23
Copy link

jonnyro23 commented Jul 19, 2016

[barButtonItem valueForKey:@"view"]

sometimes returns nil and hub not showing up

@huangboju
Copy link

view -> _view
have a try

@cwRichardKim
Copy link
Owner

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

@marcuswu0814
Copy link

@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
Copy link
Owner

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

@Lasithih
Copy link

Lasithih commented May 31, 2017

Have the same problem

@jkpang
Copy link

jkpang commented Oct 10, 2017

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

@hanks-hu
Copy link

hanks-hu commented Jan 4, 2018

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
Copy link

allaire commented Jan 24, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants