UA-17470720-3

Jump to content


Photo
- - - - -

Custom Cancel and Done in SCObjectSelectionCell detailModel (image buttons)


  • Please log in to reply
2 replies to this topic

#1 oscar.anton

oscar.anton

    Starting Out

  • STV 4.0 Pro
  • Pip
  • 6 posts
Reputation: 0
Neutral

Posted 21 May 2015 - 07:21 AM

Hi,
 
I tried to change the default navigationBar items for Done and Cancel actions in SCObjectSelectionCell detailModel and i didn't find the way to replace them with custom image buttons.
 
Somebody can help me?
 

 

Thank you in advance. 

Attached Files



#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 21 May 2015 - 09:41 AM

Hi Oscar,

 

I am surprised you have Cancel/Done buttons for SCObjectSelectionCell, since its default buttons are Back/Edit to enable you to add more objects. I am guessing you've already customized that, right?

 

Anyways, the following code will add custom done/cancel buttons with images to our CoreDataApp sample's "assignedTo" cell. Since the default STV UIBarButtonItems are system buttons, we won't be able to simply change the image and we'll need to create our own custom buttons instead (system buttons can't be modified by design in iOS).

 

// MasterViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Fetch the entity definition created in IB
    SCEntityDefinition *taskEntityDef = (SCEntityDefinition *)[self dataDefinitionWithIBName:@"TaskEntity"];
    
    // Fetch the property definition for the 'assignedTo' attribute
    SCPropertyDefinition *assignedToPDef = [taskEntityDef propertyDefinitionWithName:@"assignedTo"];
    
    // Change the button image in the detailModelWillPresent cellAction
    assignedToPDef.cellActions.detailModelWillPresent = ^(SCTableViewCell *cell, NSIndexPath *indexPath, SCTableViewModel *detailModel)
    {
        SCTableViewController *detailViewController = (SCTableViewController *)detailModel.viewController;
        
        detailViewController.navigationBarType = SCNavigationBarTypeDoneRightCancelLeft;
        
        id buttonTaget = detailViewController.doneButton.target;
        SEL doneAction = detailViewController.doneButton.action;
        SEL cancelAction = detailViewController.cancelButton.action;
        
        UIBarButtonItem *customDoneButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"done.png"] style:UIBarButtonItemStylePlain target:buttonTaget action:doneAction];
        detailViewController.navigationItem.rightBarButtonItem = customDoneButton;
        UIBarButtonItem *customCancelButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"cancel.png"] style:UIBarButtonItemStylePlain target:buttonTaget action:cancelAction];
        detailViewController.navigationItem.leftBarButtonItem = customCancelButton;
    };
}

 

Please let me know if that's what you're looking for.


  • ozie and oscar.anton like this

#3 oscar.anton

oscar.anton

    Starting Out

  • STV 4.0 Pro
  • Pip
  • 6 posts
Reputation: 0
Neutral

Posted 21 May 2015 - 01:45 PM

Thank you Tarek, it works ;)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users