2016-09-01 1 views
0

보기 컨트롤러에 segueing 문제가 있습니다. xib 테이블보기 셀이있는 테이블보기가 있습니다. 여기 내 코드가있다.다른보기 컨트롤러 테이블보기 셀 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] 
     } 
    } 

프로젝트를 만들 때 오류가 발생하지 않지만 테이블보기는 탭할 수 없습니다. 내 테이블보기를 탭할 수는 있지만 아무 것도 인쇄하지 않습니다. 내가 놓친 게 무엇입니까? pls 내게 단서를 제공합니다. 감사!

+0

에 당신이 당신의 코드에서'tableView.delegate = self'을해야합니까? – Tj3n

+0

예, 있습니다. –

+0

이상한 다음'didSelectRowAtIndexPath'가 발생해야합니다. 두 번 확인하고 중단 점을 설정하거나 다른보기가 셀 선택을 차단하는지 확인해야합니다. – Tj3n

답변

1

1)은 삭제해야합니다 :이 옵션을 사용)

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

3 :

tableView.allowsSelection = false 

2) 다른 페이지 (예를 들어, 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) 기억 : 스토리 보드에서

  • 당신이 당신의 DetailPage

  • tableViewController을 연결해야 당신은 Person에 대한 클래스를 선언하고 선언해야 :

    var PersonList = [Person]()

  • y를 선언해야합니다. 우리 vartableView 클래스와 DetailPage 클래스

0

제거 코드 행 :

tableView.allowsSelection = false 

그것은 셀의 선택을 허용하지 않습니다.