Change Back Button

Many apps that I use change the text/type of their Back button, for example when you put the view into edit mode the Back button might change to a cancel button to indicate that the effect of tapping it is to cancel the edit.

Before release it was possible to set the Back button in the view where it was shown. Then it was changed so that the Back button was set in the calling view but shown in the called view. In other words, the Back button seems to be owned by the parent view and yet it’s not possible to do:

self.parent.BackButtonTitle = "Something Else"

As an alternative approach, while I am able to remove the Back button at run-time, and add another button in its place, I am not able to put the Back button back in the navigation bar. There is an iOSToolButton.Type.Back but attempting this generates a nil button object:

button = iOSToolButton.NewSystemItem(iOSToolButton.Type.Back)

//button is nil after this so the next line throws an exception
LeftNavigationToolbar.Add(button)    

Is there any way to change the caption of the Back button, or else create a Back button, at run-time?

I’m setting the title before pushing the new view & that’s working well for me.

Self.backbuttontitle = "Cancel" Self.pushto(<new view>)

Thanks Wayne and yes, that works, but that’s not what I want to do. I want to either change the back button title (can’t do that), or else remove it altogether (can do that) and add it back again (can’t do that), from within .

The back button is part of the view you are pushing from. If you need to be able to do it on the new view, make a method that you call before calling pushto where you can pass in the old view.

Thanks @Greg O’Lone but I’m just bumping this as I’ve hit another roadblock.

I’ve tried passing in the parent view and storing it as a private property on the child view and, while this does enable me to change the mParent.BackButtonTitle as you suggest, the next issue is that tapping the Back button does not fire the child form’s ToolbarPressed event so I can’t take any action on it.

Just by way of a reminder, I originally said that:

Is there any way to get around this?

[quote=184513:@Jason Tait]Thanks @Greg O’Lone but I’m just bumping this as I’ve hit another roadblock.

I’ve tried passing in the parent view and storing it as a private property on the child view and, while this does enable me to change the mParent.BackButtonTitle as you suggest, the next issue is that tapping the Back button does not fire the child form’s ToolbarPressed event so I can’t take any action on it.

Just by way of a reminder, I originally said that:

Is there any way to get around this?[/quote]
That’s not what the back button is for. If you want to customize the behavior, add a back button yourself.

Yep. Tried that. If I remove the back button (refer to the original post) I then can’t put it back. This builds and runs but delivers a nil button:

button = iOSToolButton.NewSystemItem(iOSToolButton.Type.Back)

Perhaps I should rephrase the question. How do I use the iOSToolButton.Type.Back type to create a tool button of type back?

I’m back with another attempt to explain this issue :).

I’ve made a short video: Back Button in iOS Contacts example.

When the user puts my data entry view into Edit mode, by tapping the Edit button in the toolbar, I’d like to change the Back button to a Cancel button. It doesn’t matter what I do with the parent view, or even if I load a new instance of my view in edit mode, I can’t seem to add a Cancel button instead of a Back button. I can add a Cancel button as well as a back button but that’s not what I want. If I can’t change the Back button then I need to remove it because Xojo doesn’t fire an event when the Back button is tapped so that I can handle the cancellation of my edit. But…I can’t remove the Back button either!

In Objective-C you can simply do:

I canvassed the various options back in February and it seems the conclusion was to use a modal view. But my app uses a tabbed interface and so a modal view when in Edit mode really sticks out like a sore thumb as you lose the tab bar.

So can anybody suggest a way to either:

  1. Raise an event when the Back button is tapped; or
  2. Remove the Back button from a non-modal view?

Yes Jean-Paul! That is option #1. How do I detect the back button tap?

(I hope it’s an enhancement to dtEvents as I already have one in all the places that I need this…)