gpt4 book ai didi

ios - 从 UIButton 获取对 UIBarButtonItem 的引用?

转载 作者:行者123 更新时间:2023-11-29 02:42:58 26 4
gpt4 key购买 nike

我创建了一个基于UIButtonUIBarButtonItem。如何在事件处理程序中获取 UIBarButtonItem (!!!) 的引用?

UIButton *brigthnessButton = [[UIButton alloc]
initWithFrame:CGRectMake(0, 0, 32, 32)];
[brigthnessButton setImage:newImage forState:UIControlStateNormal];
forState:UIControlStateSelected];
[brigthnessButton addTarget:self action:@selector(createShortcut:)
forControlEvents:UIControlEventTouchUpInside];
shortCut = [[UIBarButtonItem alloc] initWithCustomView:brigthnessButton];

- (void)createShortcut:(UIButton *)button {
UIBarButtonItem *b = ???
}

最佳答案

针对您的情况

shortCut = [[UIBarButtonItem alloc] initWithCustomView:brigthnessButton];
[self.navigationItem setLeftBarButtonItem:shortCut];//if Left button

- (void)createShortcut:(UIButton *)button {

UIBarbuttonItem *b = self.navigationItem.leftBarButtonItem;
}

关于ios - 从 UIButton 获取对 UIBarButtonItem 的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25527265/

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