2014-06-30 4 views
0

Objective-C에서 수 백만 번을 수행했지만 Swift가 예상대로 작동하지 않습니다. 다음 코드는 하나의 행으로 jQuery과 셀을 채우지 않습니다 : 나는 budgetLabel 스토리 보드에 올바르게 연결된되어 있는지 확인 만든UITableView에 사용자 지정 UITableViewCell 채우기 Swift 언어 사용

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! 
    { 
     var cell = tableView.dequeueReusableCellWithIdentifier("BudgetTableViewCell", forIndexPath: indexPath) as BudgetTableViewCell 

     cell.budgetTitle.text = "My Budget" 

     return cell 
    } 

    override func numberOfSectionsInTableView(tableView: UITableView?) -> Int { 
     return 1; 
    } 


    override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int { 
     return 1; 
    } 

. 위의 모든 메소드가 호출되지만 UITableView가로드 될 때 아무 것도 표시되지 않습니다.

있는 UITableViewController 템플릿 애플이 제공 :

// #pragma mark - Table view data source 

    override func numberOfSectionsInTableView(tableView: UITableView?) -> Int { 
     // #warning Potentially incomplete method implementation. 
     // Return the number of sections. 
     return 0 
    } 

    override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int { 
     // #warning Incomplete method implementation. 
     // Return the number of rows in the section. 
     return 0 
    } 


    override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? { 

     let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) 

     // Configure the cell... 

     return cell 
    } 
+2

john doe, 나는 당신이 당신의 질문에 대답하기에 충분한 정보를 제공하지 않는다고 생각합니다. 예를 들어, 재사용 식별자에 대한 클래스를 등록 했습니까? 위임자를 구성 했습니까? 디버그 중단 점을 설정하여 코드가 호출되었는지 확인 했습니까? –

+1

디버깅을했고 코드가 호출되었습니다. Storyboard를 사용하여 클래스를 UITableViewCell에 등록했습니다. –

+0

흥미 롭습니다! 아마도이 문제는 BudgetTableViewCell 클래스에 있습니까? 콘솔에 어떤 레이아웃 경고가 전송 되었습니까? 뷰 계층 구조를 덤프하는 것은 약간의 빛을 줄 수도 있습니다. –

답변

1

jQuery과 위임 방법을 재정의 (override) 시도에서 약간 다른 인터페이스 사양을 가지고있다.

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {} 

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {} 

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {} 

귀하의 코드는 장소의 수에 ?!을 사용하여 여기에 애플의 Xcode 템플릿 코드 (마스터/세부 프로젝트)를 구현의 출발점으로 제공하는 인터페이스입니다. 이는 오버라이드 일치가 없음을 의미합니다. 대신에 새로 형식화 된 메소드를 작성하고 있습니다. 따라서 당신의 방법은 절대로 호출되지 않습니다.

참고 : UITableView, UITableView?UITableView! 사용에 관하여 마스터/세부 프로젝트에 대한 애플의 Xcode 템플릿,있는 UITableViewController의 하위 유형으로 코코아 터치 클래스 및 UITableViewDataSource 문서는 모두 일치 서명을 사용합니다.

그러나 대리자가 호출되는 경우 제공된 테이블 인수가 존재하므로 (nil이 아님) 대리자 메서드에서 UITableView!의 선언이 적절해야합니다.

+0

감사! 실제로 응용 프로그램을 디버깅하고 메서드가 호출되고 있습니다. –

+0

위의 방법을 어디에서 얻었습니까? 내가 소스에 뛰어 들면 나는 그 방법을 얻는다. 그리고! 모든 곳에. –

+0

Apple이 제공하는 정확한 템플릿을 게시 한 업데이트 된 질문을 참조하십시오. –

관련 문제