iOS: Button to access next Tableview cell
I have a main view controller which 开发者_Python百科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.
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.
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
Set them as properties and reference the classes to access them.
Use
NSUserDefaults
.
精彩评论