Is there a way to call an alertView from a tabBarItem - iphone

I am trying to implement a way for a user to logout of my app through a custom tabBarController. I have 5 tabBarItems, and I want the first one to be a logout tabBarItem - so when a user taps on it, an alertview pops up asking "are you sure you want to logout?". Is this possible - and if so what would be the best way about implementing this feature?
thanks!
-Matt

That seems like an unintuitive UI. I would consider redesigning so that there is a logout button somewhere within a view controller, toolbar or navigation bar.
With that said, if you really, really insist on making a "logout" tab bar item, you can create a UIViewController that presents a UIAlertView in viewDidAppear: and implements the UIAlertViewDelegate protocol. Then in alertView:clickedButtonAtIndex: you can update your global state to handle a logout (i.e. broadcast a notification through NSNotificationCenter, make a custom AppDelegate call, etc.).

Related

How to get a UIAlertAction from UIAlertcontroller presented when registeringForNotifications

I want to make some switches on a view controller dependant on whether a user has allowed / not to register for notifications. The very first time this view loads and
appDelegate.registerForNotifications(UIApplication.sharedApplication())
is called in ViewDidLoad the AlertController is shown and the viewController completes its layout as expected, hence missing any dependency on if the user allows / not the notifications.
I know I could present the register alert as soon as the app launches, but I want to wait to ask for permission in this view controller as it is only relevant in this view and not others before it.
Is there any way of capturing the UIAlertAction before viewWillAppear is called?
Is there any way of capturing the UIAlertAction before viewWillAppear is called?
No, nor should there be. You do not do things before viewDidLoad, viewWillAppear, and so forth. Your job in these methods is to respond as needed (for example, by doing initializations) and then get out of the way, just as fast as possible. You must not delay the appearance of the view controller in any way.
Instead, rethink your architecture.
The view controller's view is going to appear. So just let it! If you are concerned that, say, a button should not be enabled if the user disallows registration, then start out with the button disabled and only enable it after you know (or learn in the alert action's handler) that it is now allowed.
Or, if this view controller depends entirely on the user allowing registration, move registration to an earlier phase of your app, and don't even allow the user to come here without it!

Detecting if a user switches tabs inside a UITabBar on the iPhone?

Good day,
I am having a little bit of a problem. I want to track user behavior for an app. The app has a tab bar with 5 tabs. Every time a user switches tabs, I'd like to know about it. That's all I want to do.
Which method should I use here?
viewWillAppear/viewDidAppear are not getting called.
A UINavigationController actually puts this UITabBar as the UINavigationController's root view (did I describe that right?). To be very clear, the user launches the app. There are several buttons. If you press one of them, you are taken to that UITabBar with its 5 associated tabs. (In the UITabBar there is a UINavigationBar that will take you to back to the home screen.). How do I get notified when the user presses tab1, tab2, tab3, tab4, tab5--no matter which order or how many times these tabs are pressed?
Do I need a UINavigationController delegate to be implemented? If so, I'm not sure where to put that code. Or is there something simpler?
Thanks!
Look at the UITabBarControllerDelegate protocol. Set your tabBarController's delegate to self (most likely) and implement tabBarController:didSelectViewController:.
Use UITabbarControllerDelegate and provide UITabarController with delegate, which will adopt this protocol.

How to design multiple views in iPhone

I am making code for iPhone. My first screen has only one button with text Menu. When user will click on this button next screen is coming with multiple navigation bar.Each Navigation bar has their own Text information which are being selected after clicking on any Navigation bar.
How i should to design it for iPhone ? Please give me concept. Should i take multiple views ? If i have multiple views how will i hide and show on button click event ?
Thanks in advance.
You will have to adapt your user interface to comply to how Apple wants an app to work, look, and feel - or make your own custom viewcontrollers. Even then, you might not get the exact behavior you want.
My hottest tip is to look at similar apps on appstore and see how they are navigated.
I don't get a picture in my mind from your description, but it seems you want what is called "drill down". This is best done with tableViews.
You can't have multiple navigation controllers on the same "screen"; it doesn't work like that on the iPhone. Instead, what you have is one single Navigation controller, that controls the pushing of views. You decide which sub-view to push depending on which selection the user makes, and the Navigation controller handles the rest of the interaction with the user to let him or her navigate between the views.
Example structure:
Window-based app
+-MainWindow.xib
| +-First view with button
| +-UINavigationController
+-tableview1.xib
+-tableview2.xib
+-any more views you need.
Make the app delegate a <UINavigationControllerDelegate> and declare navCt *UINavigationController, and connect it in Interface Builder. You can then write a pushVC method, which takes as argument a UIViewController *vc. It does a [navCt pushViewController:vc animated:YES];
Connect the button to an IBAction, which then calls the method in the app delegate, [PushVC myVC], where myVC refers to any viewcontroller in your app, in this case table view 1.
In this table, on didSelectRow... event you can use the same method to push the sub-view table view 2.
I think this is minimum code if you are unsure about iPhone app design. Either way, I hope it gives some ideas.
You should read about UINavigationController, UITabBarController, UIViewController.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
You almost always make one view pr. viewcontroller.

Present login screen on app startup

In my previous question on UIView animations I mentioned that I have to simulate the modal behavior for some view. Here I'll explain why and ask about some better solution.
The first view a user should see in my app is the login screen. Upon successful authentication the program checks if the user is a parent or a child (in a family). For each of these roles the app must provide different functionality.
So I designed the app like this:
Declare outlets for the login view controller and a tab bar controller (for the main part of the interface) in my AppDelegate.
In the application:didFinishLaunchingWithOptions: method
Set the rootViewController of the main window to the login view controller.
Make AppDelegate the delegate for the login controller, so it can send notification when it's done its job.
When AppDelegate receives the message on successful login, it determines whether the user is a parent or a child, instantiates the set of view controllers that provide corresponding functionality and passes them to the tab bar controller.
At last AppDelegate switches the rootViewController of the main window to the tab bar controller.
Certainly the user can logout, then the rootViewController is switched back again to the login controller.
I would like to present and dismiss the login screen as if it is a modal view, but AppDelegate only has a bare window, thus I don't have an object to send presentModalViewController: to. This brings up a question:
First of all, is it a good design?
And if it is, how do I simulate a modal behavior correctly?
I think you're on the right track.
However, I always try to get out of the app delegate as soon as I can, leaving it only to do application-level things (like respond to notifications, go in and out of background). In this case, doing so will help you.
In the appDelegate, create a new UIViewController class, something like "startUpController".
Add it's view to the app window.
Then in your startUpController, do everything that you used to do in the app delegate (login, tab bar setup, etc.).
And now, since you're in a view controller, you can presentModalViewController to your hearts content.
Hii,
you should refer this
http://code.google.com/p/tweetero/
https://github.com/jbrien/WordPress-iPhone
Hope this helps!

viewWillAppear not getting called for detailView of UISplitViewController

I am experimenting with the splitViewController, introduced for iPads and am stuck at a point. I have a button on my detail view of the splitViewController, clicking on which a modal view opens. Now I want to change the positoning of UI controls on the detail view when the modal view gets dissmissed.
A pretty obvious way of doing this would be to catch the view transition in the ViewWillAppear method of the detailView. But it's not being called in this case. I remember facing the same problem in tabBarController where [tabBarController viewWillAppear:animated] was needed to be set before viewWillAppear of views in each tab item got called. I tried doing this with the splitViewController as well, but this doesn't seem to to work.
Any Ideas??
If the positioning is required due to an action that occurred in the modal view, you should use an explicit delegate callback. That will allow you to clearly specify the control flow and resulting behaviour of your app.
You should then define a protocol that has specific methods that carry pertinent information about the action taken. When the action occurs in the modal, perform the protocol method on the delegate, and it can react to that event (for you it seems to be a re-layout of button positioning).
To get an idea of the methods that are abstract enough to handle generic modal behaviour, look at UIAlertViewDelegate protocol. Here the delegate will get an alertViewCancel: message when the user decides to take no action, or alertView:didDismissWithButtonIndex: when they selected one of the options presented to them.
That is a good start for how to define the protocol.
If you need a many view controllers to react to the action taken in the modal, say a Sign In modal, then a better mechanism is notifications.