I have an NSArray of objects displayed in a UITableView.
The user can tap a cell, and the item in current row is displayed in a new view by
MYItem *selectedItem = [myItems objectAtIndex:[indexPath row]];
[itemViewController setMyItem:selectedItem];
[self navigationController] pushViewController:itemViewController
animated:YES];
This works fine. But from here,the new view, I want to add a button that takes the user to the next item in the array
-(IBAction)nextItem:(id)sender
{
// I imagine that this have to contain something like
MyItem *selectedItem =[myItems objectAtCurrentIndex+1];
...
...
}
Unfortunately, there is no such thing as objectAtCurrentIndex. Do I have to run a loop to identify the current indexnumber? or is there another way around?
An object doesn’t know his position out of the box.
A loop would be one solution. You could add an int to the object which represents the position, but you have to manage at yourself