【发布时间】:2015-02-10 03:32:21
【问题描述】:
我有一个自定义的UITableViewCell,其中有一个链接到它的类,称为customCell.m。 (我没有使用 xib。)在单元格中有一个按钮。有没有办法在mainVC.m 文件上创建按钮操作,与customCell.m 相对?
更新
这是我尝试实现的代码。我所做的是,我从mainVC.m调用了一个方法。
CustomCell.m
- (IBAction)myButton:(id)sender
{
CategorieViewController *mainVC = [[CategorieViewController alloc] init];
[mainVC myMethod];
}
MainVC.m
- (void)myMethod:(id)sender
{
UITableViewCell *clickedCell = (UITableViewCell *)[[[sender superview] superview] superview];
NSIndexPath *clickedButtonPath = [self.myTableView indexPathForCell:clickedCell];
NSLog(@"%@", clickedButtonPath);
}
CategorieViewController myMethod]:无法识别的选择器发送到实例 0x7fd2dbd52a00
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[CategorieViewController myMethod]:无法识别的选择器发送到实例 0x7fd2dbd52a00”
【问题讨论】:
-
你能显示一些代码吗?您可以创建协议或将按钮的目标添加到您正在使用 customcell 的 self 中
-
您需要致电
[mainVC myMethod:nil];。抱歉,我没有看到您的错误 -
@ChintaN-Maddy-Ramani 实际上,正如我在回答中所写,OP 必须将行更改为
[mainVC myMethod:sender];,因为 sender 参数实际上在myMethod:中使用,因此不能为 nil . -
@LyndseyScott Questioner 写了关于如何调用方法的问题。所以我没有看到错误。 (: . and ya and sender 不能为 nil。
标签: ios objective-c uibutton action custom-cell