Sha256: 7576fb9fa45a9a8d35dea5e027724d07e84a2fde87d8fdfd0cec5ef6408cb715

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

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
      
      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
    end

    def searchDisplayControllerWillBeginSearch(controller)
      @original_data = @mt_table_view_groups.clone
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
motion-table-0.1.6 lib/motion-table/searchable_table.rb