UA-17470720-3

Jump to content


Photo
- - - - -

SCObjectSelectionCell and searchBar in detail controller


  • Please log in to reply
4 replies to this topic

#1 Garrison

Garrison

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 11 posts
Reputation: 4
Good

Posted 17 October 2016 - 04:30 AM

I'm using an SCObjectSelectionCell to select an object from an array of objects, and this is is working perfectly.  But I need to be able to search the detail view that has the list of the choices.  Is there a way to make this happen easily so I can filter / search that list?



#2 Garrison

Garrison

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 11 posts
Reputation: 4
Good

Posted 17 October 2016 - 07:40 AM

Nevermind, I finally got it figured out!

 

objectSelectionCell.cellActions.detailViewController = ^UIViewController*(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        SCSearchViewController *vc = [[SCSearchViewController alloc] init];
        
        SCObjectSelectionModel *objectSelectionModel = [[SCObjectSelectionModel alloc] init];
        objectSelectionModel.searchBar = vc.searchBar;
        objectSelectionModel.enableSearchController = YES;
        objectSelectionModel.searchBar.placeholder = NSLocalizedString(@"Search", nil);
        
        vc.tableViewModel = objectSelectionModel;
        
        return vc;
    };

  • Tarek likes this

#3 Garrison

Garrison

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 11 posts
Reputation: 4
Good

Posted 17 October 2016 - 10:42 AM

Ok, so I have a follow up question now that I've got it kind of working.  I have an array of imageViews that need to be displayed with the cells as well.  I've tried using the objectSelectionModel.sectionActions.cellForRowAtIndexPath method to set the imageView, but it doesn't work because the images keep changing to the incorrect thing as you scroll up and down the table.

 

I've also tried setting itemsSection.cellsImageViews and that works, but when you use the search bar to filter the table, the images aren't also filtered, so it displays the incorrect image during the search.

 

Any idea how to solve this issue?

 

selectionCell.cellActions.detailViewController = ^UIViewController*(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        SCSearchViewController *vc = [[SCSearchViewController alloc] init];
        
        SCObjectSelectionModel *objectSelectionModel = [[SCObjectSelectionModel alloc] init];
        objectSelectionModel.searchBar = vc.searchBar;
        objectSelectionModel.enableSearchController = YES;
        objectSelectionModel.searchBar.placeholder = NSLocalizedString(@"Search", nil);
        
        vc.tableViewModel = objectSelectionModel;
        
        objectSelectionModel.sectionActions.cellForRowAtIndexPath = ^SCCustomCell*(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath)
        {
            itemsSection.cellsImageViews = _dataImageViews;
            
            SCCustomCell *cell = [SCCustomCell cellWithText:[_data objectAtIndex:indexPath.row].name];
            
            return cell;
        };
        
        return vc;
    };



#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 443
Popular

Posted 17 October 2016 - 11:06 AM

Hi Garrison,

 

I believe you should be using objectSelectionModel.cellActions.willDisplay instead of objectSelectionModel.sectionActions.cellForRowAtIndexPath.



#5 Garrison

Garrison

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 11 posts
Reputation: 4
Good

Posted 18 October 2016 - 03:36 AM

Ah ha! That helped a lot.  Thanks!!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users