-
-
Save clayallsopp/3279019 to your computer and use it in GitHub Desktop.
having trouble with bubblewrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#directory_controller.rb | |
class DirectoryController < UIViewController | |
def viewDidLoad | |
super | |
self.title = "Directory" | |
@table = UITableView.alloc.initWithFrame(self.view.bounds) | |
self.view.addSubview @table | |
@table.dataSource = self | |
@table.delegate = self | |
@data = [] | |
Person.get_people do |people| | |
@data = people | |
p "@data == #{@data}" | |
@table.reloadData | |
end | |
end | |
def push | |
new_controller = PersonController.alloc.initWithNibName(nil, bundle: nil) | |
self.navigationController.pushViewController(new_controller, animated: true) | |
end | |
def initWithNibName(name, bundle: bundle) | |
super | |
self.tabBarItem = UITabBarItem.alloc.initWithTabBarSystemItem(UITabBarSystemItemFavorites, tag: 1) | |
self | |
end | |
def tableView(tableView, numberOfRowsInSection: section) | |
p "@data in numberOfRowsInSection: #{@data}" | |
@data.count | |
end | |
def tableView(tableView, cellForRowAtIndexPath: indexPath) | |
@reuseIdentifier ||= "CELL_IDENTIFIER" | |
cell = tableView.dequeueReusableCellWithIdentifier(@reuseIdentifier) || begin | |
cell = UITableViewCell.alloc.initWithStyle(UITableViewCellSelectionStyleBlue, reuseIdentifier:@reuseIdentifier) | |
end | |
cell.textLabel.text = @data[indexPath.row]['first_name'] + " " + @data[indexPath.row]['last_name'] | |
cell | |
end | |
def tableView(tableView, didSelectRowAtIndexPath:indexPath) | |
@detail_controller ||= PersonController.alloc.init | |
@detail_controller.selected_person(@data[indexPath.row]['id']) | |
self.navigationController.pushViewController(@detail_controller, animated:true) | |
tableView.deselectRowAtIndexPath(indexPath, animated:true) | |
end | |
end | |
### person.rb | |
class Person | |
PROPERTIES = [:first_name, :last_name, :id, :function, :phone, :email, :pic_url] | |
PROPERTIES.each { |prop| | |
attr_accessor prop | |
} | |
def initialize(hash = {}) | |
hash.each { |key, value| | |
if PROPERTIES.member? key.to_sym | |
self.send((key.to_s + "=").to_s, value) | |
end | |
} | |
end | |
def self.get_people(&block) | |
BubbleWrap::HTTP.get("http://vaynernet.com/api.json") do |response| | |
p "get_people returned: #{response.body.to_str}" | |
@ppl = BW::JSON.parse(response.body) | |
p "@ppl == #{@ppl}" | |
block.call(@ppl) | |
end | |
# [{"id"=>10, "admin"=>true ... "last_name"=>"Bauch", "twitter_uid"=>nil, "avatar_file_name"=>"photo.jpeg", "updated_at"=>"2012-08-03T18:41:34Z", "first_name"=>"Sam", "start_date"=>"2012-08-03"}, ....] | |
end | |
def self.find(id, &block) | |
BubbleWrap::HTTP.get("http://vaynernet.com/api/#{id}.json") do |response| | |
@person = BW::JSON.parse(response.body) | |
p "@person == #{@person}" | |
block.call(@person) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment