2013-01-12 3 views
2

내가 RubyMotion에 새로운 해요 반환하지 않습니다. 나는 다음과 같은 오류 메시지가 실행 해요RubyMotion jQuery과 데이터 소스는 제대로

class LectureController < UIViewController 


    def viewDidLoad 
     super 

     self.view.backgroundColor = UIColor.whiteColor 

     @lectures ||= [] 

     Lecture.get() do |success, lectures| 
      if success 
       @lectures = lectures 
       p "Received #{@lectures.length} lectures" 
       @table.reloadData 
      else 
       App.alert("OOPS!") 
      end 
     end 


     @table = UITableView.alloc.initWithFrame(self.view.bounds) 
     self.view.addSubview @table 
     @table.dataSource = self 


     def tableView(tableView, numberOfRowsInSection: section) 
      @lectures.count 
     end 

     def tableView(tableView, cellForRowAtIndexPath: indexPath) 
      @reuseIdentifier ||= "CELL_IDENTIFIER" 

      cell = tableView.dequeueReusableCellWithIdentifier(@reuseIdentifier) || begin 
       UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier: @reuseIdentifier) 
      end 

      cell.textLabel.text = @lectures[indexPath.row].name 

      cell 
     end 


    end 

    def initWithNibName(name, bundle: bundle) 
     super 
     self.title = "Lectures" 
     self 
    end 

end 

:이 컨트롤러로

Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'UITableView dataSource must return a cell from 
tableView:cellForRowAtIndexPath:' 

는 최대한 멀리 볼 수있는, cellForRowAtIndexPath셀을 반환을해야합니다. 나는 왜 그것이 작동하지 않을지를 알 수 없다.

도움을 주시면 감사하겠습니다.

+0

그것은 cellForRowAtIndexPath 내에서 길잃은 "끝"이 될 수 있을까요? – Stavash

+0

아니, 그건'cell = tableView.dequeueReusableCellWithIdentifier (@reuseIdentifier)의 일부입니다. || – Ammar

답변

2

당신이 tableView 방법은 viewDidLoad 방법을 아래에 중첩된다. 그들은 메인 LectureController 클래스의 일부로 이동해야합니다.

일반적인 Ruby 클래스에서는 (viewDidLoad 메서드를 호출하면 동적으로 다른 메서드를 정의하는)이 문제를 해결할 수 있지만 코드가 변환/컴파일되는 방식 때문에 RubyMotion에서 작동하지 않습니다.

+0

감사를 차단 end' : UITableViewCell.alloc.initWithStyle (@reuseIdentifier UITableViewCellStyleDefault, reuseIdentifier를) 시작! 이전에 Rubymotion에 대해이 사실을 알지 못했습니다! : D – Ammar

+0

일반적인 루비 프로그램이라 할지라도 (당신이 할 수는 있겠지만) 이것을하지 말아야합니다. 왜냐하면'viewDidLoad'를 실행할 때마다 "이미 정의 된 메소드"에 대한 경고를 얻을 것이기 때문입니다. –