Rubymotion의 최신 버전을 사용하여 iOS 앱을 제작하고 있습니다. 원격 API의 데이터로 채우기를 원한다는 tableview가 있습니다. ProjectsController모델에서 컨트롤러로 Bubblewrap 데이터를 가져올 수 없습니다.
I 모델 이름 : 나는 API에서 프로젝트의 목록을 얻으려면 컨트롤러의 viewDidLoad에서 프로젝트
나는 컨트롤러를 지명했다. load_projects라는 프로젝트 모델에서 정적 메서드를 만들었습니다.
def viewDidLoad
super
@projects = Project.load_projects
self.navigationItem.title = "Projekt"
end
I 모델에서와 내가있는 viewDidLoad에서 같은 응답을 얻을하지 않습니다
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이다. 모델 메소드에서 올바른 응답 데이터를 얻었지만 viewDidLoad에서 "메타"객체가 리턴되었습니다. BubbleWrap :: HTTP :: Query 개체. 내가 도대체 뭘 잘못하고있는 겁니까?
업데이트 한
나는 이런 식으로 아래의 첫 번째 대답을 사용하려고하지만 오류 얻을 :
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
감사합니다 @projects와 당신이 무엇을 원하는가
을 : 대리인이 load_data 메소드를 호출, 그래서 확인되는
공지 사항보기 컨트롤러는 것을 구현! 나는 도중에 있지만 불행히도 나는 반환 된 데이터를 사용할 수 없다. 위의 업데이트 된 질문을 참조하십시오. –
이것은이 특정 질문의 범위를 벗어나므로 @person을 디버그하여 오류 메시지에 해당 객체가 없다는 것을 알기 때문에 원하는 객체인지 확인하십시오. – n00shie
mm, 무슨 뜻인지 확실하지 않습니까? @person은 무엇입니까? load_data 메소드의 요점은 나머지 컨트롤러에서 @projects를 사용할 수 있다는 것입니다. 맞습니까? –