-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmy_table_view_controller.rb
More file actions
33 lines (26 loc) · 1019 Bytes
/
my_table_view_controller.rb
File metadata and controls
33 lines (26 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class MyTableViewController < UITableViewController
BASE_URL = "http://json-lipsum.appspot.com"
def viewDidLoad
@json = {}
loadData
end
def tableView(tableView, numberOfRowsInSection:section)
@json.keys.count
end
def tableView(tableView, cellForRowAtIndexPath:indexPath)
cell = tableView.dequeueReusableCellWithIdentifier("test") || UITableViewCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier:"test")
cell.textLabel.text = @json.keys[indexPath.row]
cell.detailTextLabel.text = @json.values[indexPath.row]
cell
end
def request(request, didLoadResponse: response)
@data = response.bodyAsString.dataUsingEncoding(NSUTF8StringEncoding)
error_ptr = Pointer.new(:object)
@json = NSJSONSerialization.JSONObjectWithData(@data, options:0, error:error_ptr)
self.view.reloadData
end
def loadData
@client = RKClient.clientWithBaseURLString(BASE_URL)
@client.get("/?amount=5&what=words&start=no", delegate:self);
end
end