add tableview example

This commit is contained in:
Laurent Sansonetti
2011-09-20 11:20:15 +02:00
parent a6101e07f9
commit fe0c418add
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
$:.unshift('../../lib')
require 'rubixir/rake'
Rubixir::CONFIG.app_name = 'TableView'
Rubixir::CONFIG.device_family = :iphone

View File

@@ -0,0 +1,44 @@
class CatTableController
def initialize
@cats = {}
@cats['Tabby'] = ['Cerise', 'Kiwi']
@cats['Awesome'] = ['Nyan']
end
def numberOfSectionsInTableView(tableView)
@cats.keys.size
end
def tableView(tableView, numberOfRowsInSection:section)
sectionKey = @cats.keys[section]
@cats[sectionKey].size
end
def tableView(tableView, titleForHeaderInSection:section)
@cats.keys[section]
end
CELLID = 'CellIdentifier'
def tableView(tableView, cellForRowAtIndexPath:indexPath)
sectionKey = @cats.keys[indexPath.section]
cat = @cats[sectionKey][indexPath.row]
cell = tableView.dequeueReusableCellWithIdentifier(CELLID) || UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:CELLID)
cell.textLabel.text = cat
cell
end
end
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
tvrect = window.bounds
tv = UITableView.alloc.initWithFrame(tvrect, style:UITableViewStylePlain)
tv.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth
tv.dataSource = tv.delegate = CatTableController.new
window.addSubview(tv)
window.makeKeyAndVisible
end
end