gpt4 book ai didi

iphone - NavBar 按钮的操作不起作用

转载 作者:行者123 更新时间:2023-11-28 20:33:34 27 4
gpt4 key购买 nike

我的代码:

-(void)loadView {
[super loadView];
self.informationButton = [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeInfoLight]];
}

- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = self.informationButton;
self.informationButton.target = self;
self.informationButton.action = @selector(showHelpInfo);
}

-(void)showHelpInfo {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test"
message:@"Test"
delegate:nil
cancelButtonTitle:@"cansel"
otherButtonTitles:nil, nil];
[alert show];
}

然后我点击我的 informationButton uialertview 不显示。有我的错误吗?

最佳答案

您的 UIButton 是现在分派(dispatch)操作和事件的东西,因为此时 UIBarButtonItem 只是它的容器。因此,当您单击该按钮时,是 UIButton 拦截了触摸事件。只需创建一个与您的 UIBarButtonItem 具有相同操作的 UIButton 对象。

- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *iButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[iButton addTarget:self action:@selector(showHelpInfo) forControlEvents:UIControlEventTouchUpInside];
self.informationButton = [[UIBarButtonItem alloc] initWithCustomView:iButton];
self.navigationItem.leftBarButtonItem = self.informationButton;
}

关于iphone - NavBar 按钮的操作不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11378378/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com