多个单元格选择在tableview中 [英] Multiple cell selection In tableview
问题描述
我想将照片上传到twitter,facebook和twit pic等等。我在Array中使用了它并在Table视图中显示。我正在使用shareKit。我编码好像我选择了一个单元格(对于eg.Twitter)然后它会将照片上传到twitter我想要选择多个单元格并在一个按钮上执行此发送操作(发送到选定的行项目)。我能够标记/取消标记单元格但是如何获取单元格的选定值。我不希望它处于表的编辑模式..
I want to upload photos to twitter , facebook and twit pic and many more. I took this in Array and displayed in Table view. I am using shareKit . I coded like if I select one cell (for eg.Twitter) then It will upload photo to twitter I want to select more than one cell and perform this sending action on one button(send to selected row item). I am able to mark/unmark cells but how to get selected value of cell. I dont want it to be in table's editing mode..
代码:
- (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个对象。它应该是(私有)类实例变量。
Let sourceArray
be your array which you use to populate the tableview.
And selectedObjects
be an array of objects that are selected, initialized to contain 0 objects. It should be a (private) class instance variable.
// 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
数组中的对象来执行所需的操作。
Then in the sending action method of the button you described, use the objects in the selectedObjects
array to do the required operation.
这篇关于多个单元格选择在tableview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!