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];
but I can’t get it working. I have a UITableView *myTableView. I have used the randomized integer as the rowToSelect.
This is how I got it working. I kept the following line:
I added the following lines:
I commented the following line: