UINavigationButton & UIButton on PopToRootViewController? - iphone

My app has a sign in button and a sign up button, which are UINavigationButtons and UIButtons respectively. Either segues to a new screen that, on success, should PopToRootViewController; However, when I successfully sign in, my sign in and sign up buttons are still present. I have a method that decides whether or not to display the buttons that gets called in the viewDidLoad method. Thus, when I stop/run the app again, the buttons disappear as they should. Can anyone give me advise on how to get these buttons to hide? Thank you.
Bonus points: I also have a log out button that has a similar issue; I have to re-run the app before my view controller realizes it should hide the logout button and show the sign in/up buttons.

The problem is that viewDidLoad is only called once, so it is hardly suitable for this purpose; it has to do with the view coming into existence, and nothing to do with the interface. Use viewWillAppear: and make the decision about whether to show or hide the buttons on the basis of, say some info you've stored in NSUserDefaults (like, has the user signed in or not).

Related

How to know when user has closed modally presented controller by tapping on title?

Is there a way to know in code when user has closed a modal by tapping the title? Apple's documentation states:
The title of the modal interface is set to the string Cancel unless the presented interface controller explicitly changes it using the setTitle: method. Tapping the title dismisses the interface automatically.
As far as I know there is now way to replace that title with a button.
I could fire a notification on didDeactivate() or willDisappear() but these will also be called when app enters background. So I could do an additional check in ExtensionDelegate's applicationWillResignActive() to differentiate between user's action in my app or outside my app but this seems very fragile.
Are there any better ways?
Why would one need this?
In my case I have an initial screen where a user makes a choice. After the choice is made I present screens that contain data based on that choice.
I always want to show the data when the choice has been made. So I save the choice and present the modal on app launch when it is present.
But I don't want to show the data if the user has closed the data display. Yet I still want to display the choice made on the first screen. So I can't use the fact that the choice has been made to trigger modal displaying.
Hence I need to know if the modal has dissapeared because of user interaction in app or because the app got switched away.
Unfortunately, there is no other way to do so.
But why do you need to add additional checks at applicationWillResignActive()? I think there is no need to do so.

Storyboard iOS5 - How to prevent the storyboard changing when pressing the Segue button

I've created an app using the new iOS 5 Utility app template. Since the previous SDK, we now have to use storyboards for the GUI (which I do like using) but I am wondering how to prevent the "Segue" from flipping the view to the next view on the storyboard.
By default there is a button which when pressed flips to the "FlipsideViewController" and I would like to use this button as part of a login form but I need to stop the storyboard going to the Segue unless the credentials are correct. I have all my login code written but cannot prevent the page from flipping. The method I thought would do this actually prevents the user from going back by clicking the default "Done" button on the "FlipsideViewController".
Can anyone help?
You have to connect the button to an IBAction instead of a segue. In the action, check if the credentials are correct, then call performSegue: to perform it.
You will have to connect the segue directly from the view controller to the next scene instead of from the button.

UITabBarController Initial View?

I'm wondering if it is possible to start my app with all my tabs in the "up" state and show a "landing" view to the user. Kind of like a welcome/quick start. When they select one of the tabs, it switches views as normal.
Will you point me in the right direction?
Kind of like this:
If you're using a UITabBar/UITabBarController, I think you must have the selectedIndex set to some legal value. I don't think this is possible, nor can I find an app on my iPhone or iPod that mimics the behaviour you're looking for.
(The App Store app is as close as it gets, where it looks like it has an empty tab bar before it loads data from the Internet, but it could very well be that they are just re-using the Default.png and superimposing an activity indicator during loading.)
Note that if you tried to submit your app to Apple, they could easily reject it for using non-standard UI.
The way I would probably do this is to create a new ViewController that's just for this screen, but make sure it's last in the viewControllers array managed by the UITabBarController. That way, when you show the tab bar on the screen, you get the 4 tabs and the more button, but the currently selected view controller is not in the bar, meaning that all of the other tabs are unselected.
Once the user has satisfied the condition for showing the screen, you can discretely remove the view controller from the tab bar, and the user will never be the wiser.

iphone persistent button on all views

I have a navigation app that has many screens the user navigates to. A handful of views manages these screens dynamically. What I want to try to do is add a button that will always show up on every screen the user views. I need to do this so that the user is always able to preform the action associated with the button regardless of where they are in the app.
Is it possible to achieve this by adding this button only once and having it passed between views like my navigation bar is? Or do I just have to man up and add this button and its functionality to every single view file I have?
Thanks
I would say it probably depends on what the button does. If the button is generic to all views, meaning it affects all views the same exact way so no customization for a given view is needed, then a way to do this would be to include the function in the App Delegate or as a subclass to your Navigation controller.
You can then use the rightBarButtonItem to always show the same button and just access that method. You would just have to add code for the rightBarButtonItem in each viewDidLoad (but they'd all be the same).
I did something similar to this with an "Upgrade" button on one project. Since all the button does is launch the AppStore to the paid version, it's independent of all views and I can place it anywhere.
You can put the button on the navigation bar if you want. Alternately, the more generic way to do this would be to split your single view into two views. One is small and only contains your button but always stays on the screen. The second is your workspace and you swap in and out the views that are displaying the current content. You'll note that this is the way the navigation controls and tab-bar controls work.
The last way to do this would be to put different buttons, in the same place, on each view and have them all trigger the same action. As far as the user is concerned this looks like the same button. Disadvantage here is that you can't alter the button across all views in a simple manner.

How can we disable the button in my iphone app?

In my application, there is one button in the navigation bar. I want it to work only for the 1t click of the user. If he continousally presses on it 2 or 3 times just after the 1st click the button shouldnt recieve the following ones. How can I do this?
My app always crashes if the user presses it for more than once. I dont want to make it multithread and use lock. Thats why i want to know whether there is anyother alternative.
(If the app crashes by pressing more than once then there's a bigger problem.)
Since the button is on the navigation bar, that's a UIBarButtonItem, not a UIButton. The UIBarButtonItem has an enabled property which you can set to NO to disable the button.
(If it is really a UIButton, don't worry, it also has an enabled property.)
After the user clicked the button, you could set the "enabled" property to NO and after the action finished, set it back to YES
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIControl_Class/Reference/Reference.html#//apple_ref/occ/instp/UIControl/enabled
Luckily this is pretty easy to do. The UIBarItem class has an enabled property. Just set it to NO once the user taps it.