Turner
Turner

Reputation: 125

Go to another view controller table view cell xib

i have problem with segueing to view controller. I have table view with xib table view cell. Here is my code.

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

I have no errors when build the project, but I cant tap on my table view. I mean, I can tap on my table view, but it print nothing. What did I miss? pls give me clue. Thanks!

Upvotes: 0

Views: 618

Answers (2)

Carlo
Carlo

Reputation: 835

1) You have to delete:

tableView.allowsSelection = false

2) Use this line to pass from one cell to another page (DetailPage for example):

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

3) Use this method to pass data to a 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) Remember:

  • In your storyboard you have to link your tableViewController with your DetailPage

  • You have to declare a class for Person and declare:

    var PersonList = [Person]()

  • You have to declare your var in tableView class and in DetailPage class

Upvotes: 1

Bista
Bista

Reputation: 7903

Remove this line of code:

tableView.allowsSelection = false

It is not allowing the selection of cell.

Upvotes: 0

Related Questions