Created
November 17, 2012 21:35
-
-
Save buk/4100482 to your computer and use it in GitHub Desktop.
Load JSON Values and pass them to a UITableView - Rubymotion
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
[{"allergy":"Lactose Intolerant","created_at":"2012-11-16T23:59:10Z","date_of_birth":"2012-11-16","emergency_number":"0012345 6789","first_name":"John","group":"St. Peter","health_insurance_card":true,"id":1,"last_name":"Doe","swimmer":true,"updated_at":"2012-11-17T00:44:16Z","vaccination_certificate":false},{"allergy":"Xanax","created_at":"2012-11-17T09:50:27Z","date_of_birth":"2013-11-17","emergency_number":"0012345 6789","first_name":"John A","group":"St. Martin","health_insurance_card":true,"id":2,"last_name":"Doe","swimmer":true,"updated_at":"2012-11-17T09:50:27Z","vaccination_certificate":true},{"allergy":"None","created_at":"2012-11-17T09:51:28Z","date_of_birth":"2007-01-03","emergency_number":"0012345 6789","first_name":"John B","group":"Heiliger Franz von Asisi","health_insurance_card":false,"id":3,"last_name":"Doe","swimmer":true,"updated_at":"2012-11-17T09:51:28Z","vaccination_certificate":false}] |
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
class ParticipantsTableViewController < UITableViewController | |
def viewDidLoad | |
super | |
BW::HTTP.get("http://jugendgruppe-backend.192.168.2.105.xip.io/participants.json") do |response| | |
json = BW::JSON.parse(response.body.to_str) | |
@posts = json["items"] | |
view.addSubview(@tableView) | |
end | |
Dispatch::Queue.concurrent('mc-data').async { | |
participants_string = File.read("#{App.resources_path}/participants.json") | |
@participants = BW::JSON.parse participants_string | |
view.reloadData | |
p @participants | |
} | |
# Uncomment the following line to preserve selection between presentations. | |
# self.clearsSelectionOnViewWillAppear = false | |
# Uncomment the following line to display an Edit button in the navigation | |
# bar for this view controller. | |
# self.navigationItem.rightBarButtonItem = self.editButtonItem | |
self.navigationItem.title = "Teilnehmer" | |
end | |
def viewDidUnload | |
super | |
# Release any retained subviews of the main view. | |
# e.g. self.myOutlet = nil | |
end | |
def shouldAutorotateToInterfaceOrientation(interfaceOrientation) | |
interfaceOrientation == UIInterfaceOrientationPortrait | |
end | |
## Table view data source | |
def numberOfSectionsInTableView(tableView) | |
# Return the number of sections. | |
# @participants ? @participants.length : 0 | |
# @participants ? 1 : 0 | |
@participants ? @participants.length : 0 | |
end | |
def tableView(tableView, titleForHeaderInSection:section) | |
@participants[section]['group'] | |
end | |
def tableView(tableView, numberOfRowsInSection:section) | |
# Return the number of rows in the section. | |
@participants.length | |
end | |
def tableView(tableView, cellForRowAtIndexPath:indexPath) | |
cellIdentifier = self.class.name | |
cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) || begin | |
cell = UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:cellIdentifier) | |
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton | |
cell | |
end | |
participant = @participants[indexPath.row] | |
cell.textLabel.text = participant['first_name'] | |
cell | |
end | |
## Table view delegate | |
def tableView(tableView, didSelectRowAtIndexPath:indexPath) | |
participants_detail_table_view_controller = Participants_detailTableViewController.alloc.init | |
self.navigationController.pushViewController(participants_detail_table_view_controller, animated:true) | |
participant = @participants[indexPath.row] | |
participants_detail_table_view_controller.bind_with_participants(participant) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment