将所选联系人复制到其他UITableView IPhone

时间:2012-05-11 03:28:17

标签: iphone

我想知道,如何将选定的联系人从一个tableview复制并显示到另一个tablview。我在tableview中列出了联系人。我可以选择多选联系人。当我点击完成(选择后)我需要将选定的联系人复制到另一个tableview。有人可以指导我如何实现它。

示例或代码将非常有用。

提前致谢。

2 个答案:

答案 0 :(得分:2)

您必须拥有第一个tableview的数据源。所以你可以使用 DidSelectRowAtIndex 方法, 1)从指定的indexpath.row的datasource获取indexpath.row和copy item 到一个新的数组(它将成为你的第二个tableview的数据源。

如下所示:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//customArray is datasource for this tableview
NSString *item=    [self.customArray objectAtIndex:indexPath.row];
//arr is datasource for second tableview
    [arr addObject:item];
}
希望它有所帮助。

答案 1 :(得分:0)

lowerLblItem_Unit_Cost.text = [NSString stringWithFormat:@"%@", [delegate.addItem_UnitCost objectAtIndex:indexPath.row]];
    lowerLblItem_Unit_Cost.backgroundColor = [UIColor clearColor];

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//customArray is datasource for this tableview
NSString *item=    [self.customArray objectAtIndex:indexPath.row];
//arr is datasource for second tableview
    [arr addObject:item];

or // you can use your own label

lowerLblItem_Unit_Cost.text = [NSString stringWithFormat:@"%@", [delegate.addItem_UnitCost objectAtIndex:indexPath.row]];
    lowerLblItem_Unit_Cost.backgroundColor = [UIColor clearColor]; 

}