UA-17470720-3

Jump to content


Photo
- - - - -

Change Navigation Bar Buttons in Detail Edit View


  • Please log in to reply
11 replies to this topic

#1 Matthew Purcell

Matthew Purcell

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 84 posts
Reputation: 2
Good

Posted 17 March 2011 - 12:11 AM

Hi All,

I have a question relating to changing the navigation bar buttons on a detail edit view. When a detail edit view is shown it has the standard SCNavigationBarTypeAddEditRight which consists of an Add and Edit button (nested within a SCTransparentToolbar) as the right hand button item in the navigation bar. So, at the moment the navigation bar consists of the back button on the left hand side followed by the Add and Edit buttons on the right hand side.

Would it be possible to only display the Edit button on the right hand side and, when the Edit button is tapped and the table enters edit mode, to disappear the back button and show the Add button in its place on the left (with fade animation of course)? Then, to go back the user would need to exit edit mode (by tapping the Done button now visible on the right) to hide the Add button and show the back button once again.

I know that I could change the navigationBarType to SCNavigationBarTypeEditRight but I have had two problems with this:

1. I don't know how to get a handle on the navigationBarType for a detail edit view. I have tried various ways within the tableViewModel:detailViewWillAppearForRowAtIndexPath:withDetailTableViewModel: method but can't seem to get access to that property.

2. Even if I can get the above working, how would I tell STV to show the Add button on the left hand side when in editing mode (and assign the correct behaviour to the Add button when tapped) and re-show the back button when not in editing mode?

Thanks for any help!
Matthew

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 17 March 2011 - 07:09 AM

Hey Matthew, nice to hear back again from you :)

What you're asking for is a big part of STV 2.1 new features! :) We're also planning to give you the ability to show/hide certain cells in edit mode, in addition to having the ability to change the actual type of the cell (e.g. from static SCLabelCell to an SCTextFieldCell). We now have the design ready and we should start implementing this as soon as STV 2.0 is released (we were actually planning to have this into STV 2.0 but couldn't due to time considerations).

How urgently do you need this Matthew?

#3 Matthew Purcell

Matthew Purcell

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 84 posts
Reputation: 2
Good

Posted 17 March 2011 - 11:57 PM

Hi Tarek,

Thanks for your reply. Also good to speak with you again :)

The functionality in STV 2.1 sounds fantastic. However, is there anything I can do to get the described navigation bar button changes in STV 2.0? I am almost ready to ship my app, and I would like to make this change so that the STV generated detail views are the same as some other (non-STV) table views in the app which have this different button configuration.

Although not totally desirable, if necessary I would be happy to make the necessary changes in the core STV files just to get me through until STV 2.1 is released.

Thanks again for your help!
Matthew

#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 18 March 2011 - 03:42 AM

Hi Matthew,

Sure, if all you need is change the navigation bar buttons (but not change the cell types for example), then you can fully do that manually. Generally speaking, you're always free to whatever you want with the navigation bar, since it's not at all part of STV. However, you should keep the following in mind if you are to override the automatically generated bar buttons in STV's detail views:

1- Replacing the Add&Edit buttons on the right with an Edit button is as simple as just setting the detailTableModel.viewController.navigationItem.rightBarButtonItem property.
2- You'll be totally responsible for handling what happens when the Edit button is tapped, like showing/hiding the Add button for example.
3- Please don't forget to tie your Add button to STV's SCArrayOfObjectsSection by assigning its "addButtonItem" property to the add button.

That's about it! :) Please tell me if you need further help.

#5 Matthew Purcell

Matthew Purcell

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 84 posts
Reputation: 2
Good

Posted 19 March 2011 - 02:02 AM

Hi Tarek,

Thanks (as always) for your prompt reply. Just regarding your instructions:

1- Replacing the Add&Edit buttons on the right with an Edit button is as simple as just setting the detailTableModel.viewController.navigationItem.rightBarButtonItem property.

3- Please don't forget to tie your Add button to STV's SCArrayOfObjectsSection by assigning its "addButtonItem" property to the add button.


These two I can do.

2- You'll be totally responsible for handling what happens when the Edit button is tapped, like showing/hiding the Add button for example.


When the Edit button is tapped I would like all the STV default behavior to happen, just with the added behavior that the Add button is shown or hidden. I know what code needs to be implemented to show/hide the Add button, but how would I go about telling the STV to enter and exit editing mode?

Thanks,
Matthew

#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 19 March 2011 - 03:43 AM

Hi Matthew,

how would I go about telling the STV to enter and exit editing mode?


Prior to STV 2.1, there is nothing special that you need to tell STV to do. Just call these two lines of code (you can ommit the first line if your view controller is a UITableViewController subclass)

[tableModel.viewController setEditing:editing animated:TRUE];
[tableModel.modeledTableView setEditing:editing animated:TRUE];

Good luck!

#7 Matthew Purcell

Matthew Purcell

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 84 posts
Reputation: 2
Good

Posted 28 March 2011 - 04:12 AM

Hi Tarek,

Thanks for your message - this is working great :)

Also, apologies about my late reply (things have been absolutely flat out so I am now just catching-up on all my messages from last week!).

Best wishes,
Matthew
  • Trav likes this

#8 Matthew Purcell

Matthew Purcell

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 84 posts
Reputation: 2
Good

Posted 09 April 2011 - 08:25 AM

Hi Tarek,

A quick follow-up question on this topic which I (hope!) will be easy to answer :) As per my previous posts, I have changed the navigation bar buttons in some of the detail views. In particular, I have implemented a Cancel button in some of the detail views which include text fields (allowing the user to modify data). Obviously if they click the Cancel button I want any changes to be discarded. I have tried adding the following code to the Cancel button which successfully dismisses the view but also saves the changes:

[self dismissWithCancelValue:YES doneValue:NO];

What code can I use for the Cancel button method that will dismiss the view but NOT save the changes? In case it is relevant, this view is pushed onto a navigation stack.

Thanks,
Matthew

#9 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 12 April 2011 - 09:32 AM

Hi Matthew,

Are you subclassing STV's SCTableViewController? (just asking because, from our previous discussion, I don't recall that you do)

#10 Matthew Purcell

Matthew Purcell

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 84 posts
Reputation: 2
Good

Posted 13 April 2011 - 07:39 AM

Hi Tarek,

Thanks for your message. Yes, I am subclassing SCTableViewController. However, I have added my own custom Cancel and Done buttons to the navigation bar (as I am doing some other things on each button press in addition to the standard Cancel and Done/Save operations).

Thanks,
Matthew

#11 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 14 April 2011 - 10:19 AM

Hi Matthew,

[self dismissWithCancelValue:YES doneValue:NO] is exactly what we call ourselves when the cancel button is tapped (obviously working fine in our case :)).

How are you having STV use your own subclass instead of the default SCTableViewController? Would you please post some code? Thanks!

#12 Matthew Purcell

Matthew Purcell

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 84 posts
Reputation: 2
Good

Posted 19 April 2011 - 06:17 AM

Hi Tarek,

Well, that's odd...the problem no longer happens! I am guessing it is probably related to something else I modified in my code. Thanks anyway for your help :)

Matthew




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users