iOS: Button to access next Tableview cell

会有一股神秘感。 提交于 2019-12-25 06:26:07

问题


I have a main view controller which is a tableview, after selecting a cell from the table view, another view is displayed. How can I create buttons to access and display the next and previous cell's view? I have the toolbar and buttons set, I just need help with the code to access and push the next view.


回答1:


If you pass the data for the tableView (presumably an array containing info for the cells) to your detailViewController, then you can navigate through the items that way.

When you select a row, send the indexPath.row to the detailViewController as a property, e.g. int selectedRow. Then wire up two buttons, one that decrements this parameter and another that increments it.




回答2:


You are just looking at basic NavigationController and TableViewcontroller properties. If you want to navigate between two views then you need a Navigation Controller, and for choosing cells you need to work with the tableView.

You just need to go to the didSelectRowAtIndexPath method of your table view controller, and after selecting a row, you need to push your view controller to your next view [self.navigationController pushViewController: nextController animated:YES];. This will take control to your nextView, and you will have a back button which will bring you back to the previous view.

If you want to pass data between the views, you will need to

  1. Set them as properties and reference the classes to access them.

  2. Use NSUserDefaults.



来源:https://stackoverflow.com/questions/6779546/ios-button-to-access-next-tableview-cell

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