Skip to content

Instantly share code, notes, and snippets.

@tlehman
Created September 9, 2012 18:51
Show Gist options
  • Select an option

  • Save tlehman/3686424 to your computer and use it in GitHub Desktop.

Select an option

Save tlehman/3686424 to your computer and use it in GitHub Desktop.
Minimal UITableView datasource skeleton (with data)
class FizzBuzz
def initialize
@data = (1..100).map { |n|
out = ((n%3 == 0) ? "Fizz" : "") + ((n%5 == 0) ? "Buzz" : "")
(out == "") ? n.to_s : out
}
end
def tableView(tableView, cellForRowAtIndexPath: indexPath)
@reuse_identifier ||= "CELL_IDENTIFIER"
# return a UITableViewCell for the row
cell = tableView.dequeueReusableCellWithIdentifier(@reuse_identifier) || begin
UITableViewCell.alloc.initWithStyle(UITableViewStylePlain, reuseIdentifier:@reuse_identifier)
end
# populate the cell
cell.textLabel.text = @data[indexPath.row].to_s
return cell
end
def tableView(tableView, numberOfRowsInSection: section)
# return the number of rows
return @data.length
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment