I have two Mutable arrays. "friendsArray" contains a whole list os users and "inviteIndex" contains the indexes (indexPath.row) of some of them (get using uiswitch button into a table list).
The I fill inviteIndex array as:
[inviteIndex addObject:[NSNumber numberWithInteger:indexPath.row]];
In order to have only selected users I do:
for (int i =0; i< [inviteIndex count]; i++) {
MyElement *friend =[friendsArray objectAtIndex:[inviteIndex objectAtIndex:i] ];
NSLog(@"BUTTON PRESSED %@", friend.friendId);
}
but app crash with message:
[__NSArrayM objectAtIndex:]: index 400931632 beyond bounds [0 .. 4]'
I trid used
MyElement *friend =[friendsArray objectAtIndex:(NSInteger)[inviteIndex objectAtIndex:i] ];
with same result.
Any help please? Thanks in advance.
[inviteIndex objectAtIndex:i]
will return anNSNumber
object. You want theNSInteger
value within theNSNumber
object: