From 4d170b6bb3da47fe62baf23a7c66bdde57830328 Mon Sep 17 00:00:00 2001 From: Steve Ross Date: Fri, 17 May 2013 12:43:45 -0700 Subject: [PATCH] Added ability to use custom labels in subclassed table cells without pain --- README.md | 24 +++++++++++++++++++ lib/ProMotion/helpers/view_helper.rb | 2 +- .../_tables/_sectioned_table.rb | 15 +++++++++--- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2f13dda..767ffeb 100644 --- a/README.md +++ b/README.md @@ -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 Performance note... It's best to build this array in a different method and store it in something like @table_data. Then your table_data 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`.

 def table_data
diff --git a/lib/ProMotion/helpers/view_helper.rb b/lib/ProMotion/helpers/view_helper.rb
index da44ff4..be2b685 100644
--- a/lib/ProMotion/helpers/view_helper.rb
+++ b/lib/ProMotion/helpers/view_helper.rb
@@ -68,4 +68,4 @@ module ProMotion
     end
 
   end
-end
\ No newline at end of file
+end
diff --git a/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb b/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb
index fcc0761..221e009 100644
--- a/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb
+++ b/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb
@@ -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
\ No newline at end of file
+end