简体   繁体   English

iOS:用于访问下一个 Tableview 单元格的按钮

[英]iOS: Button to access next Tableview cell

I have a main view controller which is a tableview, after selecting a cell from the table view, another view is displayed.我有一个主视图 controller 这是一个表视图,从表视图中选择一个单元格后,会显示另一个视图。 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.如果您将tableView的数据(可能是包含单元格信息的数组)传递给您的detailViewController ,那么您可以通过这种方式浏览项目。

When you select a row, send the indexPath.row to the detailViewController as a property, eg int selectedRow .当您 select 一行时,将indexPath.row作为属性发送到detailViewController ,例如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.您只是在查看基本的NavigationControllerTableViewcontroller属性。 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.如果要在两个视图之间导航,则需要 Navigation Controller,并且要选择单元格,您需要使用 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]; 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 .使用NSUserDefaults

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM