ios - 转到另一个 View Controller TableView 单元格 xib

标签 ios swift xcode uitableview

我在继续查看 Controller 时遇到问题。我有带有 xib TableView 单元格的 TableView 。这是我的代码。

    override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    setupTableView()
    setupDataSource()
}

private func setupTableView() {
    tableView.backgroundColor = UIColor.clearColor()
    tableView.allowsSelection = false
    tableView.separatorColor = UIColor.clearColor()
    tableView.registerNib(UINib(nibName: "ExampleTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
}
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! ExampleTableViewCell
    let list = pariwisata[indexPath.row]
    cell.nameLabel.text = list.name
    cell.typeLabel.text = list.type
    let image = objects[indexPath.row]
    cell.apply(image)

    return cell
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    print("Row \(indexPath.row) selected")
}

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return tableView.bounds.width / 1.4
}

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    updateLocation(true)
}

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    updateLocation(false)
    updateLocation(true)
}

func updateLocation(running: Bool) {
    let mapView = self.view as! GMSMapView
    let status = CLLocationManager.authorizationStatus()
    if running {
        if (CLAuthorizationStatus.AuthorizedWhenInUse == status) {
            locationManager.startUpdatingLocation()
            mapView.myLocationEnabled = true
            mapView.settings.myLocationButton = true
        }
    } else {
        locationManager.stopUpdatingLocation()
        mapView.settings.myLocationButton = false
        mapView.myLocationEnabled = false
    }

}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if segue.identifier == "showTop10Detail" {
        if let indexPath = self.tableView.indexPathForSelectedRow {
            let destinationController = segue.destinationViewController as! DetailViewController
            destinationController.detpariwisata = pariwisata[indexPath.row]
        }
    }

我在构建项目时没有错误,但我无法点击我的表格 View 。我的意思是,我可以点击我的表格 View ,但它什么也不打印。我错过了什么?请给我线索。谢谢!

最佳答案

1) 你必须删除:

tableView.allowsSelection = false

2) 使用此行从一个单元格传递到另一页(例如 DetailPage):

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
            performSegueWithIdentifier("toDetailPage", sender: indexPath)
        }

3) 使用此方法将数据传递给 DetailPage:

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        let indexPath = self.tableView.indexPathForSelectedRow
        let person = personList[indexPath!.row]

        if segue.identifier == "toDetailPage"{
        let DetailBookViewController = (segue.destinationViewController as! DetailPage)
        DetailBookViewController.user_name = user_name
DetailBookViewController.user_age = user_age
            DetailBookViewController.user_urlPicture = user_urlPicture

        }

4)记住:

  • 在您的 Storyboard中,您必须将您的 tableViewController 与您的 DetailPage

  • 链接起来
  • 您必须为Person 声明一个类并声明:

    var PersonList = [Person]()

  • 您必须在 tableView 类和 DetailPage 类中声明您的 var

关于ios - 转到另一个 View Controller TableView 单元格 xib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39262141/

相关文章:

ios - 使用 Swift 5 的 Vapor 安装问题(第一次使用 Vapor)

ios - 对Casting的不完全理解

swift - 如何从url中提取不带www的域名

iphone - "Dirty"和 "Resident"与虚拟内存相关是什么意思?

ios - Xcode 8 更新后,通过桥接 header 的 .c 文件不起作用

objective-c - 更改 UIBarButtonItem 的位置

ios - 在 ios 中首次启动时, View 会全黑几秒钟, swift

ios - 如何对特定按钮使用 CADisplayLink?

ios - 多个 UiCollectionview 重新加载问题

ios - 为什么 Xcode 9 默认创建我的 socket (强、非原子)