Rubymotion の最新バージョンを使用して iOS アプリを作成しています。リモート API からのデータを入力したいテーブルビューを取得しました。
コントローラーに名前を付けました: ProjectsController
モデルに名前を付けました: Project
コントローラ viewDidLoad で、API からプロジェクトのリストを取得したいと考えています。Project モデルに load_projects という静的メソッドを作成しました。
def self.load_projects
 BW::HTTP.get("#{URL}projects?id=25&project_id=24&access_token=#{TOKEN}") do |response|
  result_data = BW::JSON.parse(response.body)
  output = result_data["projects"]
  output
 end
end
これはコントローラーの私のviewDidLoadです:
def viewDidLoad
 super
 @projects = Project.load_projects
 self.navigationItem.title = "Projekt"
end
モデルと同じ応答が viewDidLoad で得られません。モデル メソッドでは正しい応答データを取得しますが、viewDidLoad では「メタ」オブジェクトが返されます。BubbleWrap::HTTP::Query オブジェクト。私は何を間違っていますか?
1つ更新
以下の最初の回答を次のように使用しようとしましたが、エラーが発生します。
def tableView(tableView, cellForRowAtIndexPath:indexPath)
    cellIdentifier = self.class.name
    cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) || begin
      cell = UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:cellIdentifier)
      cell
    end
    project = @projects[indexPath.row]['project']['title']
    cell.textLabel.text = project
    cell
  end
エラーは次のとおりです。
projects_controller.rb:32:in `tableView:cellForRowAtIndexPath:': undefined method `[]' for nil:NilClass (NoMethodError)
2012-11-09 01:08:16.913 companyapp[44165:f803] *** Terminating app due to uncaught exception 'NoMethodError', reason: 'projects_controller.rb:32:in `tableView:cellForRowAtIndexPath:': undefined method `[]' for nil:NilClass (NoMethodError)
ここで返されたデータをエラーなしで表示できます。
def load_data(data)
    @projects ||= data
    p @projects[0]['project']['title']
  end