1) 我有一个由 View Controller 托管的简单 TableView 和由自定义 UITableViewCell
类托管的单元格。我单元格上的一个按钮会下拉菜单(一个简单的 TableView Controller 使用 FPPopoverMenu
从非主机“图片外”类加载)。
2) 问题是我想在下拉菜单行选择中更新我的按钮背景图像,这涉及我的“图片下拉菜单 TableView 类”和我的“自定义 TableView 单元格类”完全抛弃了我的自定义主机UITableViewCell
。
3) 我尝试使用 NSNotification
之类的,我成功地完成了一个只涉及主机类和下拉菜单类的简单场景,但现在它是自定义 tableview 单元格(这是一个重复实体)和下拉菜单类我想沟通..请帮助。我设置了 NSNotification
但背景图像保持不变,这意味着通知没有到达/没有及时到达。
4) 显然我需要 10 个声望才能发布图片 (:-[) 所以这是链接:
如图所示,我已经在下拉菜单的 didSelectRow 上触发了通知,当按下隐藏时,背景应该改变,如果按下显示,它应该是绿色的,就像我之前做的那样,但这没有做任何事情为我。任何帮助将不胜感激。提前谢谢你!
最佳答案
要实现此目的,您可以使用 block 。
你需要添加
@property (nonatomic, copy) void (^didSelectAction)(NSIndexPath *indexPath);
查看弹出窗口中显示的 Controller 。
比在tableView: didSelectRowAtIndexPath:
中调用此 block
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.didSelectAction)
self.didSelectAction(indexPath);
}
因此,当您创建弹出窗口时,您应该提供额外的处理程序。 像这样
向按钮添加新操作
- (UITableViewCell *) tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
[[cell button] addTarget:self action:@selector(showPopoverFromButton:) forControlEvents:UIControlEventTouchUpInside];
}
- (void) showPopoverFromButton:(UIButton *)sender {
//Your table view which is shown in popover
UITableViewController *controller = [[UITableViewController alloc] init];
[controller setDidSelectAction:^{
[sender setBackgroundColor:[UIColor redColor]];
}];
FPPopoverMenu *popover = [[FPPopoverController alloc] initWithViewController:controller];
[popover show];
}
关于ios - 使用非表格 View 主机类中的 NSNotification 更改自定义表格 View 单元格按钮背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34431166/