I'm trying to programmatically add and info button to my app's navigation. However, it doesn't ever fire the action that I'm registering to it.
UIBarButtonItem* infoButton =[[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeInfoLight]];
[infoButton setTarget:self];
[infoButton setAction:@selector(infoButtonTapped)];
The button shows up in my nav bar, but clicking on it doesn't pass into infoButtonTapped
Add the target/action to the UIButton. The bar button item behaves differently when it's set up from a UIButton.
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];
[button addTarget:self action:@selector(infoButtonTapped) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithCustomView:button];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.