尝试使用内部按钮在自定义单元格内创建IBAction

dan*_*lBB 1 objective-c uitableview ios mfmailcomposeviewcontroller

我在一个nib文件中创建了一个我自己的自定义单元格,我收到一个我不明白的错误.

[self presentViewController:_myMail animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

在这一行我收到错误No visible @interface for "LeadCell" declares the selector presentViewController:animated:completion: LeadCell是自定义控制器的名称.我想创建一个操作,用户单击该按钮,然后打开邮件编辑器视图以发送电子邮件.

任何清晰度将不胜感激.

das*_*ght 5

解决此问题的一种干净方法是将视图控制器与您的自定义单元格一起存储,如下所示:

@interface LeadCell {
    __weak UIViewController *ctrl;
}
-(id)initWithViewController:(UIViewController*)c;
...
@end

@implementation LeadCell

-(id)initWithViewController:(UIViewController*)c {
    if (self = [super init]) {
        ctlr = c;
    }
    return self;
}

@end
Run Code Online (Sandbox Code Playgroud)

在"索引路径中的行的单元格"中创建新单元格时,将视图控制器传递给单元格的初始值设定项.通过这种方式,单元格可以"找到"控制器,让您通过使用ctrl而不是self:

[ctrl presentViewController:_myMail animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)