Skip to content

Instantly share code, notes, and snippets.

@mwise
Created July 5, 2014 14:36
Show Gist options
  • Select an option

  • Save mwise/bab66be2682c1c9792f9 to your computer and use it in GitHub Desktop.

Select an option

Save mwise/bab66be2682c1c9792f9 to your computer and use it in GitHub Desktop.

Revisions

  1. mwise created this gist Jul 5, 2014.
    30 changes: 30 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    module RMExtensions
    module SearchableTable

    def setup_search_controller(opts)
    $self = self
    @search_bar = UISearchBar.alloc.initWithFrame(
    CGRectMake(0, 0, frame.size.width, 44))
    @search_controller = UISearchDisplayController.alloc
    .initWithSearchBar(@search_bar, contentsController: rmq.view_controller)

    @search_controller.delegate = self
    @search_controller.searchResultsDataSource = self
    @search_controller.searchResultsDelegate = self
    @search_controller.displaysSearchBarInNavigationBar = true

    @search_opts = opts
    end

    def searchDisplayController(controller,
    shouldReloadTableForSearchString: search_string)

    if @search_opts[:action] && @search_opts[:action].respond_to?(:call)
    @search_opts[:action].call(search_string)
    end

    !@search_opts[:async]
    false
    end
    end
    end