转到另一个视图控制器表视图单元格xib

时间:2016-09-01 03:14:09

标签: ios swift xcode uitableview tableviewcell

我遇到了查看控制器的问题。我有xib表视图单元格的表视图。这是我的代码。

    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]
        }
    }

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

2 个答案:

答案 0 :(得分:1)

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)记住:

  • 在您的故事板中,您必须将 tableViewController DetailPage

  • 相关联
  • 您必须为Person声明一个类并声明:

    var PersonList = [Person]()

  • 您必须在var课程和tableView课程中声明DetailPage

答案 1 :(得分:0)

删除这行代码:

tableView.allowsSelection = false

不允许选择细胞。