Multiple cell selection In tableview

后端 未结 5 1845
無奈伤痛
無奈伤痛 2020-12-20 03:56

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 on

5条回答
  •  情深已故
    2020-12-20 04:27

    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];
        }
    }
    

    Then in the sending action method of the button you described, use the objects in the selectedObjects array to do the required operation.

提交回复
热议问题