UIBarButtonItem: target-action not working?

后端 未结 11 925
无人及你
无人及你 2020-12-01 08:47

I\'ve got a custom view inside of a UIBarButtonItem, set by calling -initWithCustomView. My bar button item renders fine, but when I tap it, it doe

11条回答
  •  隐瞒了意图╮
    2020-12-01 09:34

    Here's how I implemented the UIButton inside of the UIBarButtonItem:

    UIButton *logoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [logoButton setImage: [UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
    logoButton.frame = CGRectMake(0, 0, 30, 30);
    [logoButton addTarget:self action:@selector(showAbout:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:logoButton];
    self.navigationItem.rightBarButtonItem = barItem;
    [barItem release];
    

提交回复
热议问题