在UITableViewController详细信息项之间移动

问题描述 投票:0回答:2

我有一个tableView,当用户选择一个单元格时,会加载一个详细视图。我希望允许用户通过单击上一个按钮或下一个按钮来浏览表示tableView中项目的详细视图。如何将其实现到我的详细视图控制器中?

ios swift uitableview segue detailsview
2个回答
1
投票

使detailViewController成为一个水平的CollectionView,启用了分页,并且与父viewController具有相同的数据源。您只需传入segue中的当前indexPath并在viewDidLoad中滚动到该indexPath。


0
投票

从你的datasource传递相同的tableViewControllerdetailViewController。同时从tableViewCell将所选detailViewController的索引传递给func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath).现在,当用户点击detailViewController上的下一个或上一个按钮时,更新您选择的索引。根据点击的下一个或上一个按钮递增或递减selectedIndex。从基于object的数组中获取当前的selectedIndex并更新您的UI。

@IBAction func nextButtonClicked(_ sender: Any) {
    selectedIndex += 1
}
@IBAction func previousButtonClicked(_ sender: Any) {
    selectedIndex -= 1
}
func updateDetailView() {
    object = dataSource[selectedIndex]
}
© www.soinside.com 2019 - 2024. All rights reserved.