【发布时间】:2016-02-15 20:55:25
【问题描述】:
我正在尝试将自定义动态图像分配给导航项;通过执行以下操作,图像显示但按钮不会触发其操作 - 它甚至不会注册点击,因为它已被禁用:
-(void) updateSanghaButton{
UIImage* sanghaImage=[[SanghaModelProvider sharedProvider] burnedImageForMeditators];
UIImageView* sanghaView=[[UIImageView alloc] initWithImage:sanghaImage];
self.sanghaNavigationButton.customView=sanghaView;
self.sanghaNavigationButton.target=self;
self.sanghaNavigationButton.action=@selector(showSangha:);
self.sanghaNavigationButton.enabled=YES;
}
相反,如果我使用代码:
UIBarButtonItem *graphButton = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed:@"GraphButton.png"]
style:UIBarButtonItemStyleBordered
target:self
action:@selector(graphButton)];
self.navigationItem.rightBarButtonItem = graphButton;
如UIBarButtonItem Custom view in UINavigationBar,按钮触发动作,但图像不显示。
我如何实现这两个目标?
【问题讨论】:
-
也许您需要重新加载导航或重新分配它
-
事实上它比我想象的要容易:[self.sanghaNavigationButton setImage:sanghaImage];完成这项工作。
标签: objective-c uibarbuttonitem