Skip to content

Instantly share code, notes, and snippets.

@tristanoneil
Created September 7, 2012 17:18
Show Gist options
  • Save tristanoneil/3667892 to your computer and use it in GitHub Desktop.
Save tristanoneil/3667892 to your computer and use it in GitHub Desktop.
class RepoController < UIViewController
def viewDidLoad
@data = []
BW::HTTP.get("https://api.github.com/users/gristmill/repos") do |response|
json = BW::JSON.parse(response.body.to_str)
json.each do |j|
@data << { name: j["full_name"], watchers: j["watchers_count"] }
end
@table = UITableView.alloc.initWithFrame(self.view.bounds)
self.view << @table
@table.dataSource = self
@table.delegate = self
end
super
end
def tableView(tableView, cellForRowAtIndexPath: indexPath)
cell = tableView.dequeueReusableCellWithIdentifier(@reuseIdentifier ||= "REPO") || begin
UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier: @reuseIdentifier)
end
cell.textLabel.text = @data[indexPath.row][:name]
cell
end
def tableView(tableView, numberOfRowsInSection: section)
@data.count
end
def tableView(tableView, didSelectRowAtIndexPath: indexPath)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
App.alert("#{@data[indexPath.row][:name]} has #{@data[indexPath.row][:watchers]} watchers.")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment