Skip to content

Instantly share code, notes, and snippets.

@jjuliano
Created July 11, 2012 20:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjuliano/3093205 to your computer and use it in GitHub Desktop.
Save jjuliano/3093205 to your computer and use it in GitHub Desktop.
[Rubymotion] UITableView and UITableViewCell using SimpleView (https://github.com/seanho/SimpleView) taken from Teacup example by Colinta (http://colinta.com/thoughts/aw_hell_its_a_table_cell.html). [refactor to use more SimpleView convention for tagging,
class MyApplicationController < UIViewController
def viewDidLoad
@data = [
{ icon: 'niftywow',
project: 'NiftyWow',
description: "Oh you just can't imagine.",
logos: ['apple', 'github']
},
{ icon: 'amazingwhizbang',
project: 'AmazingWhizBang',
description: 'Much cooler than lame stuff.',
logos: ['apple', 'twitter']
},
{ icon: 'woahsupercool',
project: 'WoahSuperCool',
description: 'No beer and no TV make Colin something something. No beer and no TV make Colin something something. No beer and no TV make Colin something something.',
logos: ['twitter', 'github']
}
]
UI::Styles.define :table,
top: 44.0,
left: 0,
width: 320,
height: 480
UI::Styles.define :cell,
style: UITableViewCellStyleDefault
UI::Styles.define :icon,
top: 5,
left: 5,
width: 40,
height: 40
UI::Styles.define :title,
font: UIFont.systemFontOfSize(17),
left: 50,
top: 0,
width: 245,
height: 20
UI::Styles.define :description,
font: UIFont.systemFontOfSize(12),
textColor: UIColor.grayColor,
lineBreakMode: UILineBreakModeWordWrap,
numberOfLines: 0,
left: 50,
top: 20,
width: 245,
height: 20
UI::Styles.define :logo1,
top: 5,
left: 295,
width: 20,
height: 20
UI::Styles.define :logo2,
top: 25,
left: 295,
width: 20,
height: 20
@table = UI::Layouts.setup(view, controller: self) do
table_view styles: :table, delegate: @controller, dataSource: @controller
end
end
def tableView(tableView, heightForRowAtIndexPath:indexPath)
50
end
def description_frame
[[50, 20], [245, 30]]
end
def tableView(tableView, cellForRowAtIndexPath:indexPath)
cell = tableView.dequeueReusableCellWithIdentifier(cell_identifier)
unless cell
cell_id = cell_identifier
cell = UI::Layouts.setup(@table) do
table_view_cell name: 'cell', styles: :cell, reuseIdentifier: cell_id do
image_view name: "icon_image_view", styles: :icon
label name: "title_view", styles: :title
label name: "description_view", styles: :description
image_view name: "logo1_view", styles: :logo1
image_view name: "logo2_view", styles: :logo2
end
end
end
project = @data[indexPath.row]
icon_image_view = cell.subview('icon_image_view')
title_view = cell.subview('title_view')
description_view = cell.subview('description_view')
logo1_view = cell.subview('logo1_view')
logo2_view = cell.subview('logo2_view')
icon_image_view.image = UIImage.imageNamed(project[:icon])
title_view.text = project[:project]
description_view.text = project[:description]
description_view.frame = description_frame
description_view.sizeToFit
# if the height is too large, it will exceed the height I want it to be, so
# I will manually just cut it off. comment these out to SEE WHAT HAPPENS :-|
frame = description_view.frame
frame.size.height = description_frame[1][1]
description_view.frame = frame
logo1_view.image = UIImage.imageNamed(project[:logos][0])
logo2_view.image = UIImage.imageNamed(project[:logos][1])
return cell
end
def cell_identifier
@@cell_identifier ||= 'Cell'
end
def tableView(tableView, numberOfRowsInSection: section)
case section
when 0
@data.length
else
0
end
end
def tableView(tableView, didSelectRowAtIndexPath:indexPath)
tableView.deselectRowAtIndexPath(indexPath, animated:true)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment