3

我正在尝试以编程方式将信息按钮添加到我的应用导航中。但是,它永远不会触发我正在注册的操作。

UIBarButtonItem* infoButton =[[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeInfoLight]];
    [infoButton setTarget:self];
    [infoButton setAction:@selector(infoButtonTapped)];

该按钮显示在我的导航栏中,但单击它不会传递到 infoButtonTapped

4

1 回答 1

11

将目标/动作添加到 UIButton。当从 UIButton 设置栏按钮项时,它的行为会有所不同。

UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];
[button addTarget:self action:@selector(infoButtonTapped) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithCustomView:button];
于 2013-06-21T17:37:30.257 回答