Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
785 views
in Technique[技术] by (71.8m points)

iphone - Multiple cell selection In tableview

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..

Code :

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


    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }


    else {

        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }



}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...