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.
Related
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.).
I'm making my first app. I use Xcode 4 with storyboard to get a better picture of whats going on. The app starts (in the storybard) with a TabBarController with 4 tabs. Two of the tabs are navigation controllers with tableview systems, and the other two tabs are regular viewcontrollers.
I've made the TabBarController itself in the Storyboard only, not made a class for it or anything. So all the tabs are "running" at the same time in the app it seems, they remain unchanged when I enter another tab and back. It looks kind of unprofessional, and maybe bad for iphone too?
Now I want to make the left tab become unactive/reset to the RootViewController when another tab is entered.
In other words make some kind of delegate function for the TabBar so only the selected tab is active. Something like that. Correct me if I'm wrong, I'm just trying to make an understanding of what I need to do.
After what I understand after my research, all I have to make a property for the TabBar in the AppDelegate.h, synthesize it in AppDelegate.m then somehow make the TabBar's delegate to AppDelegate (self ?) or something, that's done in here somehow (AppDelegate.m):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
//some statements.
then add something like this somewhere in the AppDelegate.m:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
//With some statements about the viewcontrollers
But as you see I'm not very experienced with coding, and I can't find a tutorial/guide I understand because they use xibs etc.. So can someone please help me make this function? I will need code examples to understand how to do it, if you only describe the process in words it will just make lots of new questions for me if you understand what I mean.
The classes that reprecent the 4 tabs (the 2 tableviews and the 2 views) let's call them:
FirstTableViewController, SecondTableViewController, FirstViewController, SecondViewController
I dont know if it's enough to make this function in the AppDelegate, or if I have to make a class (.h/.m) for the TabBar, add codes in the different ViewControllers classes etc.
I hope someone can help me do this in the most easy and correct way, I'm sure many others bounce into this dilemma in their beginner stage of app development and will find the answer to this very useful.
Thank you for your help.
This is the behavior that Apple intended and users expect from a tab bar based application. It allows you to view different areas of an application without losing where you are.
However, if, under certain circumstances, you want to reset a view controller back to its original state, you can do this in viewWillAppear of a given view controller.
If you want to handle this via the app delegate & tab bar controller's delegate methods, you have the reference to the tab bar after your Storyboard / XIB has loaded. Just use:
rootViewController.tabBarController.delegate = self inside of your app delegate.
Alternatively, you can change the class of tabBarController to your own custom class in the storyboard by selecting the tab bar controller in the objects list on the left pane and going to the identity inspector, changing the class from UITabBarController to a custom subclass.
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.
I have the following structure in my app, is this a correct/valid way of doing it?
UINavigationController attached to the window, the rootcontroller in this navigationcontroller is a UIViewController that presents a tableview. When a user taps one of the rows a UITabBarController is pushed on the stack.
This works, however I began to be unsure when I read this:
Because the UITabBarController class
inherits from the UIViewController
class, tab bar controllers have their
own view that is accessible through
the view property. When deploying a
tab bar interface, you must install
this view as the root of your window.
Unlike other view controllers, a tab
bar interface should never be
installed as a child of another view
controller.
This is not recommended, but it should be OK. The aweful Wordpress app also does this. This depends on the design of your app.
I'm not shure about Apple's approval.
The reason why this is not recommended (and thus might not get approved - now or at a later point!) is user confusion.
Users are used to regard the tab bar as top-level navigation. So if dig down using the table and navigation, and then getting a UITabBar, this is horrible for navigation as the user doesn't know what to expect.
The solution here, of course depending on the use case, is a "switch" in the navigation bar or a toolbar. UISegmentedControl would be a natural choice.
I am using a UITabBarController as well as a UINavigationController on my app.
In my UITabBarController I am using more than 5 items so I automatically get the 'More' item.
I've managed to add a saving procedure so the order of those items will be kept in case somebody changes the order etc.
With 'More' active I get the More navigation controller with the 'Edit' item positioned under my UINavigationController. Both navigation controller are visible. When I click on 'Edit though the More navigation controller disappears and seem to be hiding under my UINavigationController and therefore I can't see/use the 'Done' function to save my new order
What did I miss?
Cheers
It sounds like you have a UINavigationController as the main VC of your app, and a UITabBarController as one of the VC's on its stack.
I believe Apple actively discourages people from doing this in their apps, and so do I. It is never done in the iOS itself, and I have never seen it in any third-party apps either, so users will probably be confused.
I think you should embed the UINavigationController inside the UITabBarController instead of the other way around, or you could just choose to use another way of showing what you want to show.
I believe iOS does use both navigation controller and tab controller at the same time in their iPod app. The navigation controller takes you to the playing song and back and at the same time you have the tab controller when you select songs/albums/playlists etc. However, the navigation controller (or tab bar controller) seems to be custom made as it handles the More->Edit case by hiding the navigation bar underneath the Edit bar, which is not what the default UITabBarController does.
All in all, I see Apple is rather "creative" when it comes to UI design. For example, in the email app, "New" button is in the lower right corner (bottom bar) while in the SMS app the "New" button is in the upper right corner (navigation bar). I think they pretty much make custom UI to fit the individual needs of the app instead or rigidly following some consistent design.