Skip to content

Instantly share code, notes, and snippets.

@j-mcnally
Last active October 13, 2016 06:51
Show Gist options
  • Save j-mcnally/5151e2cf5cbef290ed44 to your computer and use it in GitHub Desktop.
Save j-mcnally/5151e2cf5cbef290ed44 to your computer and use it in GitHub Desktop.
Custom TableViewCell
.position_label {
width: 40px;
height: 65px;
font-size: 40px;
}
@media (orientation:portrait) {
.position_label {
left: 270px;
}
}
@media (orientation:landscape) {
.position_label {
left: 520px;
}
}
class LeaderCell < PM::TableViewCell
attr_accessor :position_label
# This method is used by ProMotion to instantiate cells.
def initWithStyle(style_name, reuseIdentifier: reuseIdentifier)
super
self.position_label = subview(UILabel, :position_label, styleClass:"position_label")
self.addSubview(self.position_label)
self
end
def setup(data_cell, screen)
cell = super(data_cell, screen)
set_leader_position
cell
end
def set_leader_position
if data_cell[:leader_position]
self.position_label.text = data_cell[:leader_position]
else
self.position_label.text = ""
end
end
end
class LeaderboardScreen < PM::TableScreen
title "Leaderboard"
refreshable callback: :on_refresh,
pull_message: "Pull to refresh",
refreshing: "Refreshing data…",
updated_format: "Last updated at %s",
updated_time_format: "%l:%M %p"
def on_refresh
my_load_data
end
def on_load
my_load_data
end
def table_data
@data ||= []
end
def my_load_data
User.find_all do |users, response|
if response.ok?
@data = [{
cells: users.each_with_index.map do |u,i|
{
cell_identifier: "LeadCellIdentifier",
cell_class: LeaderCell,
remote_image: {
url: u.avatar50,
placeholder: "50.jpg"
},
height: 70,
leader_position: "#{(i+1)}",
title: u.full_name
}
end
}]
end
end_refreshing
update_table_data
end
end
end
Copy link

ghost commented Feb 2, 2014

Nice code

@dam13n
Copy link

dam13n commented Oct 8, 2015

all hail mcnally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment