我有 UITableViewController
和行列表,我将原型(prototype)单元连接到 NavigationController
并且它是 rootViewController
,一切正常,但是一旦我选择像行 no:10 这样的行,它会进入其主细节 View ,当我单击返回按钮时,它会将我带回 UITableViewController
但这次 UITableViewController
滚动回顶部位置,它应该停留在 no:10 行,这是在我从详细 View 返回时保持我的行位置的方法吗?
swift 3,Xcode 8.2.1
class EventTableViewController: UITableViewController {
private let tableData:[Cell] = [
Cell(
image: "burj_k",
title: "Hola",
place: "DFX",
date: "SDSDs"
),
Cell(
image: "burj_k",
title: "Hola 1",
place: "DFX",
date: "SDSDs"
),
Cell(
image: "burj_k",
title: "Hola 2",
place: "DFX",
date: "SDSDs"
),
Cell(
image: "burj_k",
title: "Hola 3",
place: "DFX",
date: "SDSDs"
),
Cell(
image: "burj_k",
title: "Hola 4",
place: "DFX",
date: "SDSDs"
),
Cell(
image: "burj_k",
title: "Hola 5",
place: "DFX",
date: "SDSDs"
),
Cell(
image: "burj_k",
title: "Hola 6",
place: "DFX",
date: "SDSDs"
),
Cell(
image: "burj_k",
title: "Hola 7",
place: "DFX",
date: "SDSDs"
),
Cell(
image: "burj_k",
title: "Hola 8",
place: "DFX",
date: "SDSDs"
),
Cell(
image: "burj_k",
title: "Hola 9",
place: "DFX",
date: "SDSDs"
),
Cell(
image: "burj_k",
title: "Hola 10",
place: "DFX",
date: "SDSDs"
)
]
override func viewDidLoad() {
super.viewDidLoad()
//remembersLastFocusedIndexPath = true
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
}
最佳答案
你的结构有误,
有了这个结构,你就会有 iOS 自动返回按钮,否则你可以添加自己的,在这种情况下不需要创建 unwind segue 方法。
编辑:
如果你想要自己的后退按钮,那么你需要调用它的 Action ,
navigationController?.popViewController(animated: true)
关于ios - UITableView Selected Row Position keep stay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41712444/