
Custom Cancel and Done in SCObjectSelectionCell detailModel (image buttons)
#1
Posted 21 May 2015 - 07:21 AM
#2
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
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