I have a table which is viewed by the user. As the user shakes his device, I want a random row to be selected. How do I do this?
I have the shake gesture recognized, I can create an random integer that doesn't exceed the list count, but I can't find the right code to have that row highlighted in the table.
In Apple's documentation I found:
NSIndexPath *rowToSelect; // assume this exists and is set properly
UITableView *myTableView; // assume this exists
[myTableView selectRowAtIndexPath:rowToSelect animated:YES scrollPosition:UITableViewScrollPositionNone;
[myTableView scrollToRowAtIndexPath:rowToSelect atScrollPosition:UITableViewScrollPositionNon animate:YES];
This is how I got it working. I kept the following line:
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:randomRij inSection:0];
I added the following lines:
[eenTabelView selectRowAtIndexPath:scrollIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
I commented the following line:
//[[self eenTabelView] scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];