Skip to content

Instantly share code, notes, and snippets.

@jaunesarmiento
Last active December 28, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaunesarmiento/7453969 to your computer and use it in GitHub Desktop.
Save jaunesarmiento/7453969 to your computer and use it in GitHub Desktop.
UITableViewController required delegate methods
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