0

我正在构建一个 iPhone 应用程序,其中有一个表格视图,其中包含可以打开或关闭的项目。当用户检查了选定的项目时,我必须将该信息发送回我的服务器。但是,我不知道执行此操作的最佳方法。我应该将信息加载到数组中吗?也许是字典?你能给出具体的例子来说明如何用代码做到这一点吗?

谢谢。

没有人?

更新

需要明确的是,有关 URL 连接的所有内容都已处理。我所需要的只是一种对数组等中的信息进行排序的方法,其中项目的索引路径用于表示已检查的表格视图单元格。之后,我会将信息转换为 JSON,然后在服务器上对其进行解析。我有一个 JSON 编码/解码库,所以我不需要任何关于如何做到这一点的信息。

4

1 回答 1

0

好的,这似乎解决了我的问题。如果有人知道更优雅的解决方案,请告诉我。

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

    if ([self.tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark) {

        [self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
        [self.tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor colorWithRed:0.0 / 255 green:0.0 / 255 blue:0.0 / 255 alpha:1];
        [selectedSources removeObject:[NSNumber numberWithInt:indexPath.row]];

    } else {

        [self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
        [self.tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor colorWithRed:72.0 / 255 green:104.0 / 255 blue:152.0 / 255 alpha:1];
        [selectedSources addObject:[NSNumber numberWithInt:indexPath.row]];

    }

    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

}

selectedSources是一个 NSMutableArray,然后我对其进行 JSON 编码并发送到我的服务器。根据索引路径,我可以识别哪些表格视图单元格已被选中/未选中服务器端。

谢谢,安娜!

于 2011-07-06T18:24:23.660 回答