我在UITableView的每个单元格中都有一个按钮。现在我想每个按钮绑定到其操作方法在功能:如何在循环中设置UIButtons的动作?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ...}
这里是我试图代码:
NSString* functionNamePrefix = @"actionMethod_";
NSString* functionName = [functionNamePrefix stringByAppendingString:[NSString stringWithFormat:@"%d",indexPath.row]];
SEL selectorFromString = NSSelectorFromString(functionName);
[button addTarget:self action:@selector(selectorFromString:) forControlEvents:UIControlEventTouchDown];
失败是:行动选择采取“selectorFromString”作为一个函数的名字,但SEL我从字符串转换。
有什么建议吗? TIA!
感谢,它works.But @jrturton的答案是做我想做的正确途径。 – Maadiah 2012-07-24 02:04:51