一种更好的方法是从为表格视图提供数据的数组中获取文本并将其放入另一个数组中。我会打电话给他们sourceArray
和destinationArray
。
- (IBAction)buttonAction:(id)sender {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *string = [self.sourceArray objectAtIndex:indexPath.row];
[self.destinationArray addObject:string];
}
我怀疑该indexPathForSelectedRow
方法是您正在寻找的方法。如果您仍然需要使用标签文本,请修改处理程序,如下所示:
- (IBAction)buttonAction:(id)sender {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:indexPath];
NSString *string = selectedCell.textLabel.text;
[self.destinationArray addObject:string];
}
希望这可以帮助!