UA-17470720-3

Jump to content


Photo
- - - - -

How to change title of Edit button to "Delete"

view-controllers models sections actions

  • Please log in to reply
4 replies to this topic

#1 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 24 April 2014 - 02:46 AM

Hi,

 

I am using SCArrayOfObjectsModel to show list of items and     self.navigationBarType = SCNavigationBarTypeAddEditRight; to show Add, Edit buttons.

 

Now I want to change the edit button text as Delete.  I am trying by self.navigationItem.rightBarButtonItem.title = @"Delete"; then I am getting a right bar button as "Delete"

 

but the problem is when i select the done button(when it is in edit mode) then the button title is automatically changed to "Edit" but i want it always show as "Delete".

 

Even i tried with the following but these methods are not fired.

- (void)editingModeCancelButtonAction

- (void)editButtonAction
 

 

thanks

bala

 



#2 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 539 posts
  • LocationIreland
Reputation: 134
Popular

Posted 25 April 2014 - 06:34 AM

Hi bala,

 

Using a different SCNavigationBarType, SCNavigationBarTypeAddLeft for example,  and adding in your own Delete button with it's own actions, might be a solution.


Cheers,

Dave

www.dgapps.ie

#3 Everett

Everett

    Ev

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 191 posts
  • LocationMichigan
Reputation: 60
Outstanding

Posted 25 April 2014 - 09:34 AM

Hi Bala,

 

There are a couple of different ways to work with the navigation bar types and the different buttons.  For your approach here is a suggestion that should accomplish your requirements.

 

Use the editButtonAction method to override the edit button's behavior, and in the process you can change the title of the button.  Something like this:

 

-(void)useModelForTest {

 

    self.navigationBarType = SCNavigationBarTypeAddEditRight;

    self.editButton.title = @"Delete";

    

    SCClassDefinition *peopleDef = [SCClassDefinition definitionWithClass:[Person class] autoGeneratePropertyDefinitions:YES];

 

    SCArrayOfObjectsModel *model = [SCArrayOfObjectsModel modelWithTableView:self.tableView items:self.people itemsDefinition:peopleDef];

 

    self.tableViewModel = model;

}

 

-(void)editButtonAction {

 

    if ([self.tableView isEditing]) {

 

        [self.tableView setEditing:NO animated:YES];

        self.navigationItem.rightBarButtonItem.title = @"Delete";

    }

    else {

 

        [self.tableView setEditing:YES animated:YES];

        self.navigationItem.rightBarButtonItem.title = @"Done";

    }

}

 

I tested this in a SCTableViewController and it worked they way you suggested.  

Best of luck


Edited by Everett, 25 April 2014 - 09:34 AM.


#4 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 25 April 2014 - 05:21 PM

i would do what Dave said.. i would have said to do the same thing


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#5 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 30 April 2014 - 11:20 AM

thanks Dave and Everett, i have added my own button and achieved the same.







Also tagged with one or more of these keywords: view-controllers, models, sections, actions

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users