繁体   English   中英

使用NSNotification从非tableview主机类更改自定义tableview单元格按钮背景图像

[英]Changing custom tableview cell button background image using NSNotification from non-tableview host class

1)我有一个简单的表视图,由视图控制器托管,而单元格则由自定义UITableViewCell类托管。 我单元格上的按钮会下拉菜单(使用FPPopoverMenu从非主机“图片外”类加载的简单表格视图控制器)。

2)问题是我想更新下拉菜单行选择上的按钮背景图像,这涉及到我的“超出图片的下拉菜单tableview类”和“自定义表视图单元格类”,使我的自定义UITableViewCell宿主完全消失了。

3)我尝试使用NSNotification类的方法,我成功地完成了一个简单的场景,仅涉及主机类和下拉菜单类,但是现在它涉及到我想交流的自定义表格视图单元(它是重复实体)和下拉类。 我设置了NSNotification但是背景图片保持不变,这意味着通知没有及时到达/未及时到达。

4)显然我需要10个声誉才能发布图像(:-[),因此这里是链接:

在此处输入图片说明

如图所示,我已经在下拉菜单的didSelectRow上触发了通知,当按下“隐藏”按钮时,背景应该更改,否则,如果按了显示,则应该如图所示为绿色..就像我之前所做的那样,但这对我没有任何帮助。 任何帮助将不胜感激。 先感谢您!

为此,您可以使用块。

您需要添加

@property (nonatomic, copy) void (^didSelectAction)(NSIndexPath *indexPath);

查看弹出窗口中显示的控制器。

比在tableView: didSelectRowAtIndexPath:调用此块

- (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];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM