Last active
December 28, 2015 05:59
-
-
Save jaunesarmiento/7453969 to your computer and use it in GitHub Desktop.
UITableViewController required delegate methods
This file contains 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 MyTableViewController < UITableViewController | |
attr_accessor :datasource | |
def numberOfSectionsInTableView(table_view) | |
# Usually just 1 | |
1 | |
end | |
def tableView(table_view, numberOfRowsInSection: section) | |
# Return the count of your data source | |
@datasource.count | |
end | |
def tableView(table_view, cellForRowAtIndexPath: index_path) | |
# Set this as cell prototype identifier in Interface Builder | |
cell_id = "Cell" | |
cell = table_view.dequeuReusableCellWithIdentifier(cell_id) | |
if (cell == nil) | |
# Initialize the cell | |
cell = UITableView.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier: cell_id).autorelease | |
end | |
# Do other things to the cell here like customizing subviews, etc. | |
# Then return the cell | |
cell | |
end | |
def tableView(table_view, didSelectRowAtIndexPath: index_path) | |
# Access the selected row's data via @datasource[index_path.row] | |
puts @datasource[index_path.row] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment