可以使用performSelector:withObject:
选择传递对象。
例子:
[self performSelector:@selector(clickedInfo:) withObject:myIndex];
- (void) clickedInfo:(NSString *)itemIndex{
// some work with itemIndex
}
编辑:应该只是@selector(clickedInfo:)
而不是我收到。
编辑:使用@newacct的建议下,我建议做类似下面的内容:
- (UITableViewCell *)tableView:(UITableView)tableView cellForRowAtIndexPath:(NSIndexPath)indexPath
{
button.tag = indexPath.row;
[button performSelector:@selector(clickedInfo:)];
// or
[button addTarget:self action:@selector(clickedInfo:) forControlEvents:UITouchUpInside];
}
- (void) clickedInfo:(id)sender
{
int row = sender.tag;
// Do stuff with the button and data
}
这是不对的 –
你是对的这是不正确的,更新我的答案,但其他人已经给出了相同的例子。 –
这个问题表明他们想要设置一个按钮的动作 – newacct