ios - 从 UITableViewCell : addChildViewController unrecognized selector sent to instance 呈现 UIViewController

标签 ios objective-c uitableview alertview

我正在尝试使用 SCLAlertView 库在您单击表格 View 单元格中的按钮时显示警报 View 。我在我的 tableviewcell.m 中这样展示它:

- (IBAction)showSuccess:(id)sender {
    SCLAlertView *alert = [[SCLAlertView alloc] init];

    [alert addButton:@"First Button" target:self selector:@selector(firstButton)];

    [alert addButton:@"Second Button" actionBlock:^(void) {
        NSLog(@"Second button tapped");
    }];

    [alert showSuccess:self title:@"test" subTitle:@"test" closeButtonTitle:@"test" duration:0.0f];
}

但是当我点击按钮时,应用程序崩溃并给我这个错误:

[TableViewCell addChildViewController:]: unrecognized selector sent to instance 0x126e1bc90

它还在我实际显示警报的行上给了我这个警告:

Incompatible pointer types sending 'TableViewCell *' to parameter of type 'UIViewController *'

我猜我无法从我的 Table View Cell 中显示 View Controller,但我该如何解决这个问题?

最佳答案

您必须将单元格的父 View Controller 添加为 childViewController。

因此,在单元格中添加一个委托(delegate),将其附加到 TableViewController 中,然后在单元格委托(delegate)触发时从 TableViewController 调用警报。

关于ios - 从 UITableViewCell : addChildViewController unrecognized selector sent to instance 呈现 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29143518/

相关文章:

objective-c - 枚举的非整数基础类型

ios - 没有条目的 UITableView

ios - 将 subview 添加到 tableViewController 中的主视图将 subview 添加到 TableView 而不是 swift 中的 View

ios - 数据未显示在表格 View 中

ios - 如何从核心数据 objective-c 中的两个表中获取数据

ios - UISearchController 与 UITableView 重叠,这使我无法为单元格呈现详细的 ViewController

ios - 将 SKPhysicsJoint 添加到对象的最佳方法

ios - 使用 'LinkedIn' 登录未在真实设备中运行

ios - 按应用程序图标后的上下文菜单

objective-c - iOS:以逐渐增加的速度触发方法