如何在其他视图中显示选定的单元格值作为标签

时间:2022-12-03 10:19:06

Im new to iphone development.I have a tableview controller i want to show selected(multiple) cell(checkmarked) value as a lables in other view,How can i acheive this?this is the code which i usd for check marking the tableview cell

我是iphone开发新手。我有一个表视图控制器,我想在另一个视图中显示选定(多)单元格(复选标记)值作为标签,我如何实现它?这是我用来标记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;
}

1 个解决方案

#1


3  

Add the Checkmarked Cell's index in an array and Display the value at that index in Label

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

- (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;
            }
        }
    }
}

#1


3  

Add the Checkmarked Cell's index in an array and Display the value at that index in Label

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

- (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;
            }
        }
    }
}