Sha256: c77d46e9d44db2b293349b70e473bb58b11d4431f66dd9a4ab9094b7839fbb91

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

module ProMotion::MotionTable
  module SearchableTable
    def makeSearchable(params={})
      $stderr.puts 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)
      @mt_table_view_groups = []

      @original_data.each do |section|
        newSection = {}
        newSection[:cells] = []

        section[:cells].each do |cell|
          if cell[:title].to_s.downcase.strip.include?(searchString.downcase.strip)
            newSection[:cells] << cell
          end
        end

        if newSection.count > 0
          newSection[:title] = section[:title]
          @mt_table_view_groups << newSection
        end
      end
      
      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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ProMotion-0.1.1 lib/ProMotion/helpers/motion-table/1st/searchable_table.rb
ProMotion-0.1.0 lib/ProMotion/helpers/motion-table/first/searchable_table.rb