Iphone 带两个UIO按钮的KVO
我有一个自定义的UITableViewCell子类,它在UIPopoverController的UITableView中显示。UIPopoverController由一个UIBarbuttoneim提供 在UITableViewCell中进行选择时,我会向显示UIPopoverController的UIViewController类发送NSNotification。表中的选择将更新我的viewController中的我的视图 现在,需要另一个UIBarButtonim,它的功能与popover中UITableViewCell中的一个按钮完全相同。基本上,用例是,这个功能似乎是我们的popover中最常用的功能,他们想要一个简单的方法,只需从另一个按钮打开和关闭它 所以我所做的就是创建一个新的uibarbuttonite,并将一个目标附加到它上:Iphone 带两个UIO按钮的KVO,iphone,Iphone,我有一个自定义的UITableViewCell子类,它在UIPopoverController的UITableView中显示。UIPopoverController由一个UIBarbuttoneim提供 在UITableViewCell中进行选择时,我会向显示UIPopoverController的UIViewController类发送NSNotification。表中的选择将更新我的viewController中的我的视图 现在,需要另一个UIBarButtonim,它的功能与popover中
- (void)FilterOn:(id)sender {
isFilterOn = !isFilterOn;
if ([sender isKindOfClass:[UIBarButtonItem class]]) {
UIBarButtonItem *filter = (UIBarButtonItem *)sender;
if (isFilterOn) {
[filter setTitle:@"Filter On"];
[self DoFilter];
}
else {
[aboutMeBBI setTitle:@"Filter Off"];
[self ClearFilter];
}
}
}
所以这部分是有效的。它会更新模型,按钮的标题也会更改。问题是,假设我打开了过滤器,然后在popover中,我关闭了过滤器。我将通知传递给viewController类的普通更新方法,该方法处理过滤和一系列其他内容。我在弹出窗口中按下过滤器按钮时添加了以下简单片段:
- (void)FilterSortOptionDidSelect:(NSNotification *)notification {
NSDictionary *userDict = [notification userInfo];
NSInteger theTag = [[userDict objectForKey:@"CellTag"] integerValue];
switch (theTag) {
case FILTER: {
// update Model
[self.FilterBarButtonItem setTitle:@"Filter off"];
}
break;
default:
break;
}
}
但这并不是我想要的,因为如果我再次单击filter按钮,首先,如果我再次单击filter按钮,它仍然会说filter Off,并执行filter Off操作,然后如果我再次单击它,它将执行filter on操作。我试图在switch语句中通过更改标题来伪造它,但这并不是我真正想要做的。我读了一些关于键值观察的内容,我不确定是否可以在这里使用类似的方法,将我的按钮状态注册为UIPopoverController中UITableViewCell子类中的按钮状态。如果有人有任何想法那就太好了。谢谢