-
-
Save j-mcnally/5151e2cf5cbef290ed44 to your computer and use it in GitHub Desktop.
Custom TableViewCell
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
.position_label { | |
width: 40px; | |
height: 65px; | |
font-size: 40px; | |
} | |
@media (orientation:portrait) { | |
.position_label { | |
left: 270px; | |
} | |
} | |
@media (orientation:landscape) { | |
.position_label { | |
left: 520px; | |
} | |
} |
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 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 |
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice code