多个单元格选择在tableview
我想上传照片到twitter,facebook和twit图片等等。我把它放在数组中并显示在表格视图中。我正在使用shareKit。我编码就好像我选择了一个单元格(例如,Twitter),然后它将上传照片到Twitter我想选择多个单元格并在一个按钮上执行发送操作(发送到选定的行项目)。我能够标记/取消标记细胞,但如何获得选定的细胞值。我不希望它是在表的编辑模式..多个单元格选择在tableview
代码:
- (void) tableView:(UITableView *)atableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
让sourceArray
成为您用来填充tableview的数组。 和selectedObjects
是一个被选中的对象数组,被初始化为包含0个对象。它应该是一个(私有)类实例变量。
//NSMutableArray *selectedObjects = [[NSMutableArray array] retain];
- (void) tableView:(UITableView *)atableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
YouObjectType *object = [sourceArray objectAtIndex:indexPath.row]; //This assumes that your table has only one section and all cells are populated directly into that section from sourceArray.
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
[selectedObjects removeObject:object];
}
else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[selectedObjects addObject:object];
}
}
在您所描述的按钮的发送动作方法
然后,使用对象selectedObjects
数组中进行所需的操作。
感谢您的回复 – iProgrammer 2011-05-12 06:17:16
使用cellforRowAtIndexPath的错误想法。好的一点是将所有的项目选择状态保存在一个数组中,并在这里选中/取消选中它。然后调用reloadData。 – 2012-04-05 08:00:45
您可以在阵列管理它是哪个小区选择或没有,当你在didSelectRowAtIndexPath方法更新选择一行然后该数组根据上述条件并在上传图像时使用该数组。例如 - 你有一个数组,其中有两个对象,分别是key @“image”和@“isSelected”,并用这个数组填充表,当你选择一行时,从数组中访问元素作为字典对象indexPath.row并更新该字典“真”或“闪亮”键“isSelected”。
你可以参考任何例子或链接? – iProgrammer 2011-05-12 05:46:49
在didSelectRowAtIndexPath中获取indexPath.row,您可以知道选择了哪个单元。
您也可以使用复选标记的tableview喜欢它..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
的HTTP重复:/ /stackoverflow.com/questions/308081/is-it-possible-to-configure-a-uitableview-to-allow-multiple-selection和http://stackoverflow.com/questions/3040894/uitableview-multiple-selection – 2011-05-12 05:55:40
@ IphoneDeveloper,如果你有正确的答案你为什么不给这个努力的加票? – 2012-01-03 04:51:29