gpt4 book ai didi

ios - UIBarButton 的点击事件如何处理

转载 作者:搜寻专家 更新时间:2023-10-31 22:33:09 28 4
gpt4 key购买 nike

由于UIBarButton 不是继承自UIResponder/UIControlUIBarButton 上的点击事件是如何工作的?

最佳答案

Just create the UIBarButtonItem's target and action properties directly.

UIBarButtonItem *barListBtn = [[UIBarButtonItem alloc] initWithTitle:@"yourTitle" 
style:UIBarButtonItemStylePlain
target:self action:@selector(btnClicked:)];
self.navigationItem.rightBarButtonItem = barListBtn;



-(void)btnClicked:(UIBarButtonItem*)btn
{
NSLog(@"button tapped %@", btn.title);
}

选择 2

- (void) viewDidLoad
{
[super viewDidLoad];

// first we create a button and set it's properties
UIBarButtonItem *myButton = [[UIBarButtonItem alloc]init];
myButton.action = @selector(doTheThing);
myButton.title = @"Hello";
myButton.target = self;

// then we add the button to the navigation bar
self.navigationItem.rightBarButtonItem = myButton;


}


// method called via selector
- (void) doTheThing {

NSLog(@"Doing the thing");

}

一些额外的 Sample

关于ios - UIBarButton 的点击事件如何处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35403135/

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