lib/motion-table/searchable_table.rb in motion-table-0.1.6 vs lib/motion-table/searchable_table.rb in motion-table-0.1.7

- old
+ new

@@ -1,13 +1,23 @@ module MotionTable module SearchableTable - def makeSearchable - searchBar = UISearchBar.alloc.initWithFrame(CGRectMake(0, 0, 320, 44)) - @contactsSearchDisplayController = UISearchDisplayController.alloc.initWithSearchBar(searchBar, contentsController: self) - @contactsSearchDisplayController.delegate = self - @contactsSearchDisplayController.searchResultsDataSource = self - @contactsSearchDisplayController.searchResultsDelegate = self + def makeSearchable(params={}) + params[:frame] ||= CGRectMake(0, 0, 320, 44) + params[:contentController] ||= self + params[:delegate] ||= self + params[:searchResultsDataSource] ||= self + params[:searchResultsDelegate] ||= self + + searchBar = UISearchBar.alloc.initWithFrame(params[:frame]) + if params[:searchBar] && params[:searchBar][:placeholder] + searchBar.placeholder = params[:searchBar][:placeholder] + end + + @contactsSearchDisplayController = UISearchDisplayController.alloc.initWithSearchBar(searchBar, contentsController: params[:contentController]) + @contactsSearchDisplayController.delegate = params[:delegate] + @contactsSearchDisplayController.searchResultsDataSource = params[:searchResultsDataSource] + @contactsSearchDisplayController.searchResultsDelegate = params[:searchResultsDelegate] self.tableView.tableHeaderView = searchBar end def searchDisplayController(controller, shouldReloadTableForSearchString:searchString) @@ -31,9 +41,10 @@ true end def searchDisplayControllerWillEndSearch(controller) @mt_table_view_groups = @original_data.clone + @original_data = nil end def searchDisplayControllerWillBeginSearch(controller) @original_data = @mt_table_view_groups.clone end \ No newline at end of file