Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在自定义表视图单元格中执行操作将不起作用_Ios_Objective C_Uitableview_Uiviewcontroller - Fatal编程技术网

Ios 在自定义表视图单元格中执行操作将不起作用

Ios 在自定义表视图单元格中执行操作将不起作用,ios,objective-c,uitableview,uiviewcontroller,Ios,Objective C,Uitableview,Uiviewcontroller,我有一个自定义的表视图单元类。在牢房里我有一个按钮。当我点击单元格中的按钮时,我想显示一个弹出视图,事实上我使用的是RNBlurModalView 因为它是一个UITableViewCell类,我不能使用self,所以我尝试在自定义单元格内创建UIViewController,如下所示: __weak UIViewController *ctrl; -(IBAction)openView { RNBlurModalView *modal = [[RNBlurModalView allo

我有一个自定义的表视图单元类。在牢房里我有一个按钮。当我点击单元格中的按钮时,我想显示一个弹出视图,事实上我使用的是RNBlurModalView

因为它是一个UITableViewCell类,我不能使用self,所以我尝试在自定义单元格内创建UIViewController,如下所示:

__weak UIViewController *ctrl;
-(IBAction)openView {
    RNBlurModalView *modal = [[RNBlurModalView alloc] initWithViewController:ctrl title:@"Title" message:@"Hello"];
    [modal show];
}
显示弹出窗口的代码如下所示:

__weak UIViewController *ctrl;
-(IBAction)openView {
    RNBlurModalView *modal = [[RNBlurModalView alloc] initWithViewController:ctrl title:@"Title" message:@"Hello"];
    [modal show];
}
因此,我尝试使用initWithViewController:ctrl来代替initWithViewController:self。但当我点击按钮时,什么也没发生


如何解决此问题?

自定义tableView单元格是UIView的子类,您想在其中显示UIViewController是不对的。您必须告诉包含当前tableView的viewController才能为您完成这项工作。我建议您使用委托模式将消息传递给viewController。 例如:

委托方法的实现

- (void)showTheModalView
{
   RNBlurModalView *modal = [[RNBlurModalView alloc] initWithViewController:ctrl title:@"Title" message:@"Hello"];
   [modal show];
}
和单元内实现

-(IBAction)openView {
//RNBlurModalView *modal = [[RNBlurModalView alloc] initWithViewController:ctrl title:@"Title" message:@"Hello"];
//[modal show];
[self.delegate showTheModalView];
}

声明的委托

@protocol SomeDelegate <NSObject>
- (void)showTheModalView;
@end

它无法工作,应用程序崩溃。我应该如何在cell类中创建委托?像这样@属性强的非原子id委托;