Added ability to use custom labels in subclassed table cells without pain

This commit is contained in:
Steve Ross
2013-05-17 12:43:45 -07:00
parent 92bfb2c3e2
commit 4d170b6bb3
3 changed files with 37 additions and 4 deletions

View File

@@ -461,6 +461,25 @@ your Rakefile and doing this:
]
```
A note about table screens. You may not want a sectioned table. In that case,
use only one section and set its value to `nil`. For example:
```ruby
[ {:title=>nil,
:cells=>[
{:title=>"37th Annual Grammy Awards", :subtitle=>"Nokia Theater"}
]
},
{:title=>nil,
:cells=>[
{:title=>"87th Academy Awards", :subtitle=>"Nokia Theater"}
]
},
{:title=>nil,
:cells=>[{:title=>"Golden Globe Awards", :subtitle=>"Beverly Hilton"}]}
]
```
## Using your own UIViewController
Sometimes you want to inherit from a different UIViewController other than that provided by ProMotion,
@@ -767,6 +786,11 @@ end</code></pre>
<strong>Performance note...</strong> It's best to build this array in a different method
and store it in something like <code>@table_data</code>. Then your <code>table_data</code>
method just returns that.
It's common to add labels to a subclassed tableview cell, so ProMotion finds any attributes
that end in `_label` in your input hash and tries to assign to them without going through the
hoop-jumping of using `:cell_class_attributes`. This only applies to tables cells where you have
declared a `:cell_class`.
<pre><code>
def table_data

View File

@@ -68,4 +68,4 @@ module ProMotion
end
end
end
end

View File

@@ -1,12 +1,12 @@
module ProMotion::MotionTable
module SectionedTable
include ProMotion::ViewHelper
def table_setup
PM.logger.error "Missing #table_data method in TableScreen #{self.class.to_s}." unless self.respond_to?(:table_data)
self.view = self.create_table_view_from_data(self.table_data)
if self.class.respond_to?(:get_searchable) && self.class.get_searchable
self.make_searchable(content_controller: self, search_bar: self.class.get_searchable_params)
end
@@ -158,6 +158,15 @@ module ProMotion::MotionTable
table_cell.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin
end
### Catch any custom class labels ###
if data_cell[:cell_class]
data_cell.select{|k| k =~ /_label$/}.each_pair do |k, v|
puts "setting #{k} to #{v}"
puts "getting #{table_cell.send(k)}"
table_cell.send(k).setText v
end
end
if data_cell[:cell_class_attributes]
set_attributes table_cell, data_cell[:cell_class_attributes]
end
@@ -267,4 +276,4 @@ module ProMotion::MotionTable
trigger_action(cell[:action], cell[:arguments]) if cell[:action]
end
end
end
end