Jump to content

- - - - -

Override editButton action.

general view-controllers

  • Please log in to reply
2 replies to this topic

#1 Sam Gerardi

Sam Gerardi

    Jr. Member

  • STV 3.0 Std
  • PipPip
  • 27 posts
  • LocationSan Diego, CA
Reputation: 5

Posted 12 November 2012 - 06:04 PM

Is there a way to override partial functionality of the edit button in a SCTableViewController? I need to perform some tasks based on the value of two tableview cells, but only if they are both valid. In version 2 I was able to override the editButtonAction method. This method is not available in version 3.

Here is the long version of what I am trying to accomplish...

I have two text field cells bound to a core data object. Each of these cells is validated using the .required property. In addition, I need to validate the combined value of the two cells. When the doneButton is pressed while editing I need to evaluate the combined value and if it is...

valid: perform a task, save the changes, end editing;
invalid: display an alert, prevent changes from being saved, don't end editing.

In the past I would override the -(void)doneButtonAction: as follows...

if (combined values are valid)
[do task]; [super doneButtonAction];
else (combined values are not valid)
[display alert]; [reload bound values];

It seems that this method has been removed in version 3. I am not looking for realtime validation. The most logical place to perform these actions would be when the doneButton is pressed.

Thoughts? Thank you!

Attached Files

#2 Tarek


    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452

Posted 12 November 2012 - 08:30 PM

Hi Sam,

I think what you're looking for is the SCTableViewModelDelegate method called 'tableViewModel:shouldDismissDetailViewForRowAtIndexPath:withDetailTableViewModel:cancelButtonTapped:doneButtonTapped:' .

#3 Sam Gerardi

Sam Gerardi

    Jr. Member

  • STV 3.0 Std
  • PipPip
  • 27 posts
  • LocationSan Diego, CA
Reputation: 5

Posted 12 November 2012 - 09:06 PM

I tried this and as well as the other model and controller delegate methods that pass the button pressed in them. I also tried to use the will/didBeginEditing delegates but I wasn't able to get the right functionality. There doesn't appear to be a way to prevent the controller from leaving editing mode from within a delegate.

The controller is just a standalone instance of SCTableViewController. It isn't being presented by another SCTableViewController as a detail view. I could use my own editButton, but Im not sure how I invoke the default editButton behaviors. Is there another way to accomplish this?

This may be a good opportunity for a feature request...
- (BOOL)tableViewControllerShouldBeginEditing:cancelButtonTapped:doneButtonTapped
- (BOOL)tableViewControllerShouldEndEditing:cancelButtonTapped:doneButtonTapped.
It would be awesome to be able to just override the editButtonAction as well.

Also tagged with one or more of these keywords: general, view-controllers

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users