3

我是 iphone 开发新手。我有一个 tableview 控制器,我想在其他视图中将选定(多个)单元格(选中标记)值显示为标签,我怎样才能做到这一点?这是我用来检查标记 tableview 单元格的代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
    thisCell.accessoryType = UITableViewCellAccessoryCheckmark;

}else
{
    thisCell.accessoryType = UITableViewCellAccessoryNone;
}
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellAccessoryNone;
}
4

1 回答 1

3

在数组中添加选中标记单元格的索引并在标签中显示该索引处的值

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
    if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
        thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
        [myIndexArray addObject:[NSString stringWithFormat:@"%d",indexPath.row]];
    }
    else
    {
        thisCell.accessoryType = UITableViewCellAccessoryNone;
        for(int i=0; i<myIndexArray.count; i++)
        {
            if([[myIndexArray objectAtIndex:i]intValue]== indexPath.row)
            {
                [myIndexArray removeObjectAtIndex:i];
                 break;
            }
        }
    }
}
于 2012-09-08T07:31:21.130 回答