2017-03-09 3 views
0

다른 오류가 수정되었습니다 만, 지금은 numberOfRowsInSection에서자기와 numberOfInSections

import UIKit 

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 
    override func viewDidLoad() { 
     super.viewDidLoad() 
    } 
    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    return UITableViewCell() 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 5 
} 
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     self.performSegue(withIdentifier: "meunSegue", sender: self) 

     func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    } 
} 
    let secondViewController = segue.destination as! SecondViewController 


class SecondViewController: UIViewController { 

    var recievedData = "" 
    override func viewDidLoad() { 
     super.viewDidLoad() 
     print(recievedData) 
    } 
} 
} 
+0

클래스에서 numberRowsOfInSection을 어디에 정의 했습니까? 원하는 행 수 (Int 값)를 반환하고 numberOfRowsInSection 메서드 다음에 클래스 범위를 끝냈습니다. 준비 방법 후에 끝내라. – Sahil

답변

0

! "SecondViewController로 secondViewController = segue.destination하자"또 다른 해결되지 않은 식별자를 얻고 당신은 행의 수를 반환해야 현재는 numberRowsOfInSection을 반환하지만 ViewController에는 numberRowsOfInSection의 신고가 없습니다. 따라서 tableView으로 원하는 행 수를 반환하십시오. 당신이있는 tableView에서 볼 대신의 dequeue 셀을 한 다음 원하는 레이블 텍스트를 설정하고 셀을 반환 할 수 있도록

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return 5 
} 

또한 cellForRowAt 당신은 UITableViewCell() 빈 셀을 반환한다.

참고 : 코드에서 당신이 당신의 클래스 외부 didSelectRowAtprepareForSegue 방법을 추가 한, 당신은 것을 추가 할 필요가 클래스 내부.

+0

고맙지 만 이제는 또 다른 해결되지 않은 식별자 "segue"가 있습니다. secondViewController – Alexis

+0

@Alexis 새 코드로 질문을 편집하십시오. –

+0

@Alexis'prepareForSegue' 메소드 안에 그 라인을 추가하십시오. 또한'overrideFor' 접두어를'prepareForSegue' 메쏘드 / –