Reputation: 3107
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;
}
}
Upvotes: 2
Views: 2952
Reputation: 6322
You can use this github repo JLSelectionTVC (https://github.com/nvrtdfrst/JLSelectionTVC) which accomplishes this
Upvotes: 0
Reputation: 3979
You can also make it using check mark in tableview like..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
Upvotes: 1
Reputation: 26197
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.
Upvotes: 3
Reputation:
Get indexPath.row in didSelectRowAtIndexPath, you can know which cell was selected.
Upvotes: 0
Reputation: 11145
You can manage it in an array that which cell is selected or which not, when you select a row then in didSelectRowAtIndexPath update that array according to above condition and use that array when you are uploading images. For example - u have an array which have dictionary two objects for key @"image" and @"isSelected" and populate the table with this array and when you select a row then access the element from array as a dictionary object at indexPath.row and update that dictionary "true" or "flase" for key "isSelected".
Upvotes: 0