开发者

How to load next/previous Cell from UITableView?

I have saved values in a NSArray. If I click on a cell in the tableView it loads the V开发者_Go百科alues from the Array in the fields. What if I want to load the values from the next/previous cell in the fields when I click a Button?

Thanks for all answers.


Your question is pretty unclear so I'm answering it the best I can.

You have the indexPath.row of the cell you clicked on right?

You can access the previous cell using:

UITableViewCell *previousCell = (UITableViewCell*)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row - 1 inSection:indexPath.section]];

Similarly for the next cell:

UITableViewCell *nextCell = (UITableViewCell*)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section]];

I assume you'll handle all the cases where your current row is the first/last row so you don't want to try and access rows before/after that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜