How to jump to the next row in detailview

喜欢而已 提交于 2019-12-03 21:37:07

With your UITableView, you can get the selected row by:

- (NSIndexPath *)indexPathForSelectedRow

And set the selection by incrementing the indexPath.row:

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition

then you action could be:

-(IBAction)nextCell:(id)sender {
  NSIndexPath * actualIndexPath = myTableView.indexPathForSelectedRow;
  NSIndexPath * newIndexPath = [NSIndexPath  indexPathForRow:actualIndexPath.row+1 inSection:actualIndexPath.section];
  [myTableView selectRowAtIndexPath:newIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}

for that you can manage with your DataSource array.

when you load your detail view at that time you pass your index of array(indexPath.row). by that index you fetch data in detail view. and using increment and decrement in that index you get data for next and previous cell.

Steps

1) setup your tableView.

2) when redirect to DetailView at that time set one int variable for store current indexPath.row . so define one int in detail View.

3) using next and previous button manage indexpath.row which is in int variable. and represent appropriate data from Source array.

You can use:

(UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

To get the cell you want (next or previous).

And then set the returned cell "Selected" property to YES.

cell.selected = YES

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!