Last active
December 30, 2015 12:19
-
-
Save yestoall/7828487 to your computer and use it in GitHub Desktop.
UITableView auto layout problem with TeaCup
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 Search < UIViewController | |
# ------------------------------------------------------------------------------------- | |
stylesheet :search | |
layout do | |
@back = subview UIView, :back | |
@logo = subview UIView, :logo do | |
@logo_image = subview UIView, :logo_image | |
end | |
@title = subview UIView, :title do | |
@title_label = subview UILabel, :title_label, text: "search"._ | |
end | |
@arrow_up = subview UIView, :arrow_up | |
@table = subview UITableView, :table, delegate: self, dataSource: self | |
hh = BAGDevice.height() | |
ww = BAGDevice.width() | |
ww_half = ww/2 | |
auto do | |
metrics "margin" => 20 | |
vertical "|-36-[logo(==100)]-margin-[title(==30)]-margin-[table(>=1)]-45-|" | |
vertical "|-(>=1)-[arrow_up(==16)]-15-|" | |
horizontal "|-#{ww_half-50}-[logo(==100)]-#{ww_half-50}-|" | |
horizontal "|-18-[title]-18-|" | |
horizontal "|-#{ww_half-16}-[arrow_up(==32)]-#{ww_half-16}-|" | |
horizontal "|[table]|" | |
end | |
end | |
# ------------------------------------------------------------------------------------- | |
def numberOfSectionsInTableView table | |
# ------------------------------------------------------------------------------------- | |
1 | |
end | |
# ------------------------------------------------------------------------------------- | |
def tableView table, numberOfRowsInSection:section | |
# ------------------------------------------------------------------------------------- | |
BAG.search_result.count() | |
end | |
# ------------------------------------------------------------------------------------- | |
def tableView table, cellForRowAtIndexPath:index_path | |
# ------------------------------------------------------------------------------------- | |
cell_id = "search_cell" | |
cell = table.dequeueReusableCellWithIdentifier(cell_id) || SearchCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:cell_id) | |
cell.on_content(index_path.row) if BAG.search_result[index_path.row] | |
cell | |
end | |
# ... other stuff | |
end | |
# | |
# ------------------------------------------------------------------------------------- | |
class SearchCell < UITableViewCell | |
# ------------------------------------------------------------------------------------- | |
include Teacup::Layout | |
stylesheet :search | |
# ------------------------------------------------------------------------------------- | |
def initWithStyle style, reuseIdentifier: identifier | |
# ------------------------------------------------------------------------------------- | |
super | |
layout(self.contentView) do | |
@back = subview UIView, :back | |
@logo = subview UIView, :logo do | |
@logo_image = subview UIView, :logo_image | |
end | |
@title = subview UIView, :title do | |
@title_label = subview UILabel, :title_label, text: "in your BAG"._ | |
end | |
@arrow_up = subview UIView, :arrow_up | |
@table = subview UITableView, :table, delegate: self, dataSource: self | |
hh = BAGDevice.height() | |
ww = BAGDevice.width() | |
ww_half = ww/2 | |
auto do | |
metrics "margin" => 20 | |
vertical "|-36-[logo(==100)]-margin-[title(==30)]-margin-[table(>=1)]-45-|" | |
vertical "|-(>=1)-[arrow_up(==16)]-15-|" | |
horizontal "|-#{ww_half-50}-[logo(==100)]-#{ww_half-50}-|" | |
horizontal "|-18-[title]-18-|" | |
horizontal "|-#{ww_half-16}-[arrow_up(==32)]-#{ww_half-16}-|" | |
horizontal "|[table]|" | |
end | |
self.accessoryType = UITableViewCellAccessoryNone | |
self.selectionStyle = UITableViewCellSelectionStyleNone | |
self | |
end | |
# ... other stuff | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment