如何在 iPhone 的表格视图中实现滑动
我有一个表格视图。我把它分成3部分。 我想在这个表格视图中实现滑动。当我在表视图中滑动时,将加载下一个视图。 如何实施? 提前致谢
i have a table view. i divided it into 3 sections.
i want to implement swipe in this tableview. when i swipe in table view, next view will be loaded.
How to implement this?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您基本上有两个选择:
I:使用 UISwipeGestureRecognizer
因为我从未使用过它,所以我可以告诉您关于这种方式的信息。只需查看官方文档以获取更多信息。您应该知道,它是在 iOS 3.2 中引入的,因此不支持未运行 iOS 4.0 的 iPhone,因此尤其是第一代 iPhone 将被排除在外。
II:覆盖touchesBegan/Moved/Ended
阅读这篇文章了解更多信息,此应该正是您所需要的。当然,这个解决方案不仅适用于 UITableViews,而且适用于从 UIResponder 继承的每个类(因此适用于每个 UIView)。
You have basically two options:
I: Use UISwipeGestureRecognizer
Since I never worked used it, there is not much I can tell you about this way. Just see the official documentation for further information. You should know, that it was introduced with iOS 3.2, so there is no support for iPhones which are not running iOS 4.0, so especially firstGen iPhones will be excluded.
II: Overwrite touchesBegan/Moved/Ended
Read this post for further information, this should be exactly what you need. Of course, this solution does not only work for UITableViews but for every class that inherits from UIResponder (and consequently for every UIView).
通常,您的表视图控制器将实现
UITableViewDelegate
协议。当用户触摸表视图中的某一行时,将调用tableView:didSelectRowAtIndexPath:
方法。如果实现该方法,则可以使用传入的NSIndexPath
的row
和section
属性来确定用户在表中的哪一行已选择。根据选择,您可以创建或初始化要加载的适当的下一个视图控制器,然后将新控制器推送到表视图控制器的navigationController
上。有关更多信息,请尝试阅读:
Generally, your table view controller will implement the
UITableViewDelegate
protocol. ThetableView:didSelectRowAtIndexPath:
method is called when the user touches one of the rows in your table view. If you implement the method, you can userow
andsection
properties of theNSIndexPath
that are passed in to determine which row in you table the user selected. Based on the selection, you can then create or initialize the appropriate next view controller that you want to load and then push the new controller on the table view controller'snavigationController
.For further info, try reading: