我是 iphone 开发的新手。我有一个 tableview Controller ,我想在其他 View 中将选定的(多个)单元格(选中的)值显示为标签,我该如何实现?这是我用于复选标记的代码表格 View 单元格
- (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;
}
最佳答案
将勾选单元格的索引添加到数组中,并在标签中显示该索引处的值
- (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;
}
}
}
}
关于iphone - 如何将表格 View 中的选定单元格值显示为其他 View 中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12328811/