UA-17470720-3

Jump to content


Photo
- - - - -

SearchBar inside TableView


  • Please log in to reply
5 replies to this topic

#1 Urkman

Urkman

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 59 posts
Reputation: 17
Good

Posted 24 June 2013 - 05:42 AM

Hello,

 

what is the best way to add a SearchBar to a TableView? So it only shows up, when the user swipes down the TableView?

It should work like the Music App :)

 

Thanks,

Urkman


Edited by Urkman, 24 June 2013 - 05:46 AM.


#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 27 June 2013 - 10:33 AM

Hi Urkman,

 

You should simply add it to the tableView's tableHeaderView:

 

self.tableViewModel.tableView.tableHeaderView = mySearchBar;

 

Let me know if you need any more help.



#3 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 27 June 2013 - 11:39 AM

Hi Urkman,

 

You should simply add it to the tableView's tableHeaderView:

 

 

self.tableViewModel.tableView.tableHeaderView = mySearchBar;

 

Let me know if you need any more help.

 

Tarek! :D

 

Is it possible to have that same functionality (only show when user swipes down) when using the SCSearchViewController?

 

Thanks!


Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#4 Urkman

Urkman

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 59 posts
Reputation: 17
Good

Posted 01 July 2013 - 11:37 AM

Hi Tarek,

 

self.tableViewModel.tableView.tableHeaderView = mySearchBar;

 

When I try this, I get this error:

 

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
*** First throw call stack:
(0x313f52a3 0x390d997f 0x31340b75 0x1ace1b 0x1adb39 0x1875dd 0x1a1d25 0x1a8899 0x18afdd 0x33232fef 0x3321e02b 0x3321e599 0x3321e40d 0x3327222b 0x139937 0x1392b7 0x3321c595 0x3327114b 0x33271091 0x33270f75 0x33270e99 0x332705d9 0x332704c1 0x332414e9 0x33200803 0x32faad8b 0x32faa929 0x32fab85d 0x32fab243 0x32fab051 0x32faaeb1 0x313ca6cd 0x313c89c1 0x313c8d17 0x3133bebd 0x3133bd49 0x34f032eb 0x33251301 0xfd5c9 0xfd550)
libc++abi.dylib: terminate called throwing an exception

 

Thanks,

Urkman



#5 Little i Apps LLC

Little i Apps LLC

    Starting Out

  • STV 3.0 Pro
  • Pip
  • 4 posts
Reputation: 2
Good

Posted 29 July 2013 - 09:11 AM

Urkman and Tarek,

 

  I'm getting a similar problem, in a limited scope.  Whenever I type a 'k' into the search box, I get this:

 

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 8 beyond bounds [0 .. 7]'

 

Any and all help would be appreciated!

 

Thanks,

Ryan



#6 Little i Apps LLC

Little i Apps LLC

    Starting Out

  • STV 3.0 Pro
  • Pip
  • 4 posts
Reputation: 2
Good

Posted 29 July 2013 - 12:42 PM

Update: I figured out where I was getting this error.  When I was configuring my cells in tableViewModel.cellActions.willConfigure, I was doing this: 

if ([[boundDictionary objectForKey:@"cellType"] isEqualToString:@"project"]) {
            //Configure Project Cell
            customCell.height = 64;
            //For cell reuse - get rid of cell status
            for (UIView *subview in [cell.contentView subviews]) {
                if (subview.tag == 5) {
                    subview.backgroundColor = [UIColor clearColor];
                }
            }
            //Job check and configuration
            NSArray *associatedJobs = [boundDictionary objectForKey:@"jobs"];
            if ([associatedJobs count] > 0) {
                for (int i = 1; i <= [associatedJobs count]; i++) {
                    NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:([indexPath row]+i) inSection:[indexPath section]];
                    if ([newIndexPath row] < [[self.tableViewModel sectionAtIndex:0] cellCount]) {
                        SCCustomCell *customCell = (SCCustomCell*)[self.tableViewModel cellAtIndexPath:newIndexPath];
                        if ([[[cellArray objectAtIndex:[indexPath row]+i] valueForKey:@"hidden"]  isEqualToString:@"TRUE"]) {
                            //currently hidden - unhide
                            customCell.height = 50;
                            customCell.hidden = FALSE;
                            //change the cell's button as well
                            [self setAccessoryImageForHidden:TRUE forCell:cell];
                        }
                        else{
                            customCell.height = 0;
                            customCell.hidden = TRUE;
                            //change the cell's button as well
                            [self setAccessoryImageForHidden:FALSE forCell:cell];
                        }
                    }
                }
            }
            else{
                [cell setAccessoryView:nil];
            }
        }

I have 'Project' cells and 'Job' cells, with each project having between 0 and many jobs.  I was trying to configure job cells that may or may not exist in the search results by indiscriminately configuring every job cell.  In the code posted above, I run a safety check to make sure I am within the bounds of the search results (line 195) before running any further configuration.  Voila!

 

  Urkman, my guess is that somewhere you are also trying to configure cells without checking if they exist in the search results.  I hope this helps!

 

-Ryan


  • wizgod likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users