gpt4 book ai didi

ios - UIBarButton 不执行操作

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

我遇到了一个问题:我在我的 UiNavigation Controller 中以编程方式创建了一个 UIBarButton。但是,我希望它在按下时发出警报。但是,当我使用带有自定义文本的自定义栏按钮时,它不起作用:

self.navigationItem.rightBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Subscribe" style:UIBarButtonItemStyleDone target:nil action:@selector(subscribe:)];

self.navigationItem.rightBarButtonItem = addButton;

但是当我做一个普通的条形按钮时,它工作正常:

self.navigationItem.rightBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(subscribe:)];

self.navigationItem.rightBarButtonItem = addButton;

这里是空白:

-(void)subscribe:(id)sender {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Highscore" message:@"" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];

[alert show];

}

提前致谢,拉菲

最佳答案

替换 nil 你在 init 调用中作为 target: 传递

[[UIBarButtonItem alloc] initWithTitle:@"Subscribe" 
style:UIBarButtonItemStyleDone
target:nil <---
action:@selector(subscribe:)];

self 。您的 alloc init 应如下所示:

[[UIBarButtonItem alloc] initWithTitle:@"Subscribe" 
style:UIBarButtonItemStyleDone
target:self
action:@selector(subscribe:)];

发送给 nil 的消息不会有任何效果 ;-)

关于ios - UIBarButton 不执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18557447/

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