gpt4 book ai didi

objective-c - 更改 customView 后 UIBarButtonItem 不再响应

转载 作者:搜寻专家 更新时间:2023-10-30 19:44:09 24 4
gpt4 key购买 nike

PO(NSStringFromSelector(self.editSettings.action));
[self.editSettings setCustomView:imageView]; //works if this is commented out but with bad image
PO(NSStringFromSelector(self.editSettings.action));

该代码生成

2013-01-17 11:47:41.184 BadgerNew[29570:c07] NSStringFromSelector(self.editSettings.action): Setting:
2013-01-17 11:47:41.185 BadgerNew[29570:c07] NSStringFromSelector(self.editSettings.action): Setting:

所以选择器还是一样的。

但是,在 [self.editSettings setCustomView:imageView] 之后;不能再按下按钮。按下它没有任何效果。

我认为 customView 可能会“吸收”用户交互。

但是,我无法设置 imageView.userInteractionEnabled。没有这样的选择器。

我错过了什么?

这似乎不是问题所在。我添加了更多控制台打印。它表明 imageView userInteractionEnabled 已默认为 false

UIImage * imageSetting= [UIImage imageNamed:@"setting-button"];
UIImageView * imageView = [[UIImageView alloc]initWithImage:imageSetting];
PO(NSStringFromSelector(self.editSettings.action));//Bar Button Item
self.editSettings.customView =imageView;
PO(NSStringFromSelector(self.editSettings.action));
PO(@(imageView.userInteractionEnabled));
PO(self.editSettings.customView);
PO(imageView);
imageView.userInteractionEnabled=false;

然后我尝试了一个完全没有 Interface Builder (IB) 的解决方案并执行:

UIImage * imageSetting= [UIImage imageNamed:@"setting-button"];
UIImageView * imageView = [[UIImageView alloc]initWithImage:imageSetting];
self.editSettings = [[UIBarButtonItem alloc]initWithCustomView:imageView];
self.editSettings.action = @selector(Setting:);

self.navigationItem.leftBarButtonItem = self.editSettings;

还是不行。

有人说自定义 View 需要是按钮而不是图像。好吧,我想知道。

最佳答案

来自文档:

初始化自定义 View :

初始化自定义 View :

Initializes a new item using the specified custom view. - (id)initWithCustomView:(UIView *)customView Parameters

customView

A custom view representing the item.

Return Value

Newly initialized item with the specified properties. Discussion

The bar button item created by this method does not call the action method of its target in response to user interactions. Instead, the bar button item expects the specified custom view to handle any user interactions and provide an appropriate response. Availability

关于objective-c - 更改 customView 后 UIBarButtonItem 不再响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14372398/

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