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;
还是不行。
有人说 customView 需要是按钮而不是图像。嗯,我想知道。