Initial pass at a refreshable table.

This commit is contained in:
Mark Rickert
2013-05-06 12:56:56 -04:00
parent d96cf40625
commit c8c0c43c49
5 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
module ProMotion::MotionTable
module RefreshableTable
def make_refreshable
@refresh = UIRefreshControl.alloc.init
@refresh.attributedTitle = NSAttributedString.alloc.initWithString("Pull to Refresh")
@refresh.addTarget(self, action:'refreshView:', forControlEvents:UIControlEventValueChanged)
self.refreshControl = @refresh
# @on_refresh = get_refreshable_block
# params[:content_controller] ||= params[:contentController]
# params[:data_source] ||= params[:searchResultsDataSource]
# params[:search_results_delegate] ||= params[:searchResultsDelegate]
# params[:frame] ||= CGRectMake(0, 0, 320, 44) # TODO: Don't hardcode this...
# params[:content_controller] ||= self
# params[:delegate] ||= self
# params[:data_source] ||= self
# params[:search_results_delegate] ||= self
# search_bar = UISearchBar.alloc.initWithFrame(params[:frame])
# search_bar.autoresizingMask = UIViewAutoresizingFlexibleWidth
# if params[:search_bar] && params[:search_bar][:placeholder]
# search_bar.placeholder = params[:search_bar][:placeholder]
# end
# @contacts_search_display_controller = UISearchDisplayController.alloc.initWithSearchBar(search_bar, contentsController: params[:content_controller])
# @contacts_search_display_controller.delegate = params[:delegate]
# @contacts_search_display_controller.searchResultsDataSource = params[:data_source]
# @contacts_search_display_controller.searchResultsDelegate = params[:search_results_delegate]
# self.table_view.tableHeaderView = search_bar
end
alias :makeRefreshable :make_refreshable
######### iOS methods, headless camel case #######
# UIRefreshControl Delegates
def refreshView(refresh)
refresh.attributedTitle = NSAttributedString.alloc.initWithString("Refreshing data...")
@on_refresh.call if @on_refresh
end
def on_refresh(&block)
@on_refresh = block
end
def end_refreshing
return unless @refresh
@refresh.attributedTitle = NSAttributedString.alloc.initWithString("Last updated on #{Time.now.strftime("%H:%M:%S")}")
@refresh.endRefreshing
self.update_table_data
end
end
end

View File

@@ -7,6 +7,9 @@ module ProMotion::MotionTable
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
if self.class.respond_to?(:get_refreshable) && self.class.get_refreshable
self.make_refreshable
end
end
# @param [Array] Array of table data

View File

@@ -1,6 +1,7 @@
module ProMotion::MotionTable
module GroupedTable
include SectionedTable
include RefreshableTable
def table_view
@table_view ||= UITableView.alloc.initWithFrame(self.view.frame, style:UITableViewStyleGrouped)

View File

@@ -2,6 +2,7 @@ module ProMotion::MotionTable
module PlainTable
include SectionedTable
include SearchableTable
include RefreshableTable
def table_view
@table_view ||= UITableView.alloc.initWithFrame(self.view.frame, style:UITableViewStylePlain)

View File

@@ -2,6 +2,7 @@ module ProMotion
module TableScreenModule
include MotionTable::PlainTable
include MotionTable::SearchableTable
include MotionTable::RefreshableTable
include ProMotion::ScreenModule
def update_table_data
@@ -9,6 +10,7 @@ module ProMotion
end
module TableClassMethods
# Searchable
def searchable(params={})
@searchable_params = params
@searchable = true
@@ -21,6 +23,17 @@ module ProMotion
def get_searchable
@searchable ||= false
end
# Refreshable
def refreshable(&block)
@refreshable_block = block
@refreshable = true
end
def get_refreshable
@refreshable ||= false
end
end
def self.included(base)
base.extend(ClassMethods)