Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

TableView Search Bar issue

Hello all. I'm facing crash issues or general malfunction when dealing with a search bar that is attached to a tableview. Basically, if the tableview has no data or all of its rows have been deleted, activating the search bar leads to a crash (trying to alter the search properties leads to no effect).
Can someone confirm this issue for me please or suggest a good workflow for quickly filtering table row entries in a dynamic table?
Using Ti Mobile SDK 1.1.2 - iphone project. Thank you very much.

— asked March 31st 2010 by Sunder Iyer
  • iphone
  • searchbar
  • tableview
0 Comments

2 Answers

  • This has happened to me as well.

    One solution might be to hide the search bar when the table is empty:

    tableView.setData(data);
    
    if(data.length)
    {
        tableView.search.show();
    }
    else
    {
        tableView.search.hide();
    }
    

    The search bar should initially be hidden too, unless the table view holds data upon creation before setData is called.

    — answered April 1st 2010 by James K
    permalink
    1 Comment
    • .show() and .hide() worked great. Was pulling my hair out. Thanks.

      — commented August 12th 2011 by Ken Rucker
  • Don't attached the search bar to the tableView. Attach it to the window or view that contains both.

    var win1 = Titanium.UI.createWindow({  
        //...
    });
    var search = Titanium.UI.createSearchBar({  
        //...
    });
    var searchResults = Titanium.UI.createTableView({
        //...
    });
    
    //Add everything to the window
    win1.add(search);
    win1.add(searchResults);
    win1.open();
    

    Make sense?

    — answered August 9th 2010 by Clifton Labrum
    permalink
    1 Comment
    • How does the table know to filter results by the search bar if you don't do:

      table.search = search;
      

      And if you do that it adds it to the tableview. Am I corect?

      — commented May 4th 2011 by Joe iEntry
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.