Reputation: 16296
My purpose is when the user click on a button in view1
(to go to the view2
), i will send all the selected cells from UITableView
just checked in view1
to the view2
.
So before passing the table to next view, i wanted to test if i am on the right track, but seems not. This is my code:
-(IBAction)goToView2{
//get all section selectioned items into an array
themesChosed=[tView indexPathsForSelectedRows];//tView is the outlet of my UITableView and themesChosed is an NSArray declared in the .h file
for (int i=0; i<=[themesChosed count]; i++) {
NSLog(@"%i",[[themesChosed objectAtIndex:i]integerValue]);
}
}
This always returning me a single 0.
2012-01-13 15:52:06.472 MyApp[876:11603] 0
Although i selected several items on the table.
Upvotes: 2
Views: 2155
Reputation: 177
If you are not getting index values then best approach wound be as below to access index number:
NSArray *indexes = [self.tableView indexPathsForSelectedRows];
for (NSIndexPath *path in indexes) {
NSUInteger index = [path indexAtPosition:[path length] - 1];
[selectedOptionsArray addObject:[optionHolderArray objectAtIndex:index]];
}
Upvotes: 0
Reputation: 34912
The objects in themesChosed
are NSIndexPath
objects. You'll want to access the row
and section
properties like so:
-(IBAction)goToView2{
//get all section selectioned items into an array
themesChosed=[tView indexPathsForSelectedRows];//tView is the outlet of my UITableView and themesChosed is an NSArray declared in the .h file
for (int i=0; i<=[themesChosed count]; i++) {
NSIndexPath *thisPath = [themesChosed objectAtIndex:i];
NSLog(@"row = %i, section = %i", thisPath.row, thisPath.section);
}
}
Upvotes: 5
Reputation: 7931
First NSIndexPath
is not an integer, it is an object with row and section methods, so that is probably why you get a zero. Are you sure you have allowsMultipleSelection
set to YES?
Upvotes: 2