forked from HipByte/RubyMotionSamples
/
beer_list_controller.rb
40 lines (34 loc) · 1.26 KB
/
beer_list_controller.rb
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
34
35
36
37
38
39
40
class BeerListController < UITableViewController
def initWithDetailsController(beer_details_controller)
@beer_details_controller = beer_details_controller
if init
self.tabBarItem = UITabBarItem.alloc.initWithTitle('List', image:UIImage.imageNamed('list.png'), tag:1)
end
self
end
def viewDidLoad
view.dataSource = view.delegate = self
end
def viewWillAppear(animated)
navigationController.setNavigationBarHidden(true, animated:true)
end
def tableView(tableView, numberOfRowsInSection:section)
Beer::All.size
end
CELLID = 'CellIdentifier'
def tableView(tableView, cellForRowAtIndexPath:indexPath)
cell = tableView.dequeueReusableCellWithIdentifier(CELLID) || begin
cell = UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:CELLID)
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton
cell
end
beer = Beer::All[indexPath.row]
cell.textLabel.text = beer.title
return cell
end
def tableView(tableView, accessoryButtonTappedForRowWithIndexPath:indexPath)
beer = Beer::All[indexPath.row]
navigationController.pushViewController(@beer_details_controller, animated:true)
@beer_details_controller.showDetailsForBeer(beer)
end
end