iphone - 如何将表格 View 中的选定单元格值显示为其他 View 中的标签

标签 iphone ios uitableview

我是 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/

相关文章:

ios - 单元格如何为 UITableView 删除

ios - MBProgressHUD 阻止用户与 TableView 的交互

iphone - 如何在 iOS 上的按钮操作上显示忙碌指示器?

ios - 从 MPRemoteCommandCenter 丢失 "Now Playing"状态

ios - 如何创建 overlaySKScene SWIFT Xcode 来显示 HUD 或控件?

ios - 手机重启后,远程通知未发送到我的应用程序

iPhone/iPad 应用程序开发限制

iphone - 付款被拒绝。请在您的计算机上为此金额添加有效的付款方式。 (iOS 中的 PayPal 实时模式)

iPhone使用iTunes传输文件,但不允许用户查看所有文档目录?

swift - UIButton 无法在 UITableViewCell 中的所有设备上居中 - Swift