ios - UITableView Selected Row Position keep stay

标签 ios swift uitableview

我有 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()
}
}

Story board

最佳答案

你的结构有误,

有了这个结构,你就会有 iOS 自动返回按钮,否则你可以添加自己的,在这种情况下不需要创建 unwind segue 方法。

New structure

编辑:

如果你想要自己的后退按钮,那么你需要调用它的 Action ,

navigationController?.popViewController(animated: true)

关于ios - UITableView Selected Row Position keep stay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41712444/

相关文章:

ios - Alamofire/Moya SSL 请求因 ATS 系统信任失败而失败。 X 的系统信任失败

iphone - 使用 NSData 更新 GKTurnBasedMatch 中的回合

swift - Sprite Kit 和类型推断

ios - 我如何计算 Swift 2 中坐标的反射

iphone - setIndentationLevel 不适用于 cell.ContentView subview

ios - 通过代码错误使用refreshcontrol刷新tableView

ios -/Fabric.framework/运行 : Permission denied

IOS如何检查数组的值是否包含某个值并将其显示出来

ios - MVC - 没有 UIKit 的模型文件中的 NSFetchRequest

ios - ios-Uitableviewcell中的Uilabel和UIimageview