I am trying to implement custom tab bar and custom side menu in one iOS application, like in the new Facebook iOS application. I tried with following links https://github.com/mikefrederick/MFSideMenu and https://github.com/isaacueca/3dglobe/tree/4648fed5915cef53c58f3e54efadf0f512446e59/xCode/UniversialGlobe/Classes with DDKCustomTabbar classes, however when I am trying to put them both using this code:
[self.window addSubview:sideMenu.view];
[self.window addSubview:tabbar.view];
tabbar overlays the sideMenu and opposite.
A few quick points,
Your trying to add them both to the window, which is almost certainly not what you want. Instead you want to set a single root view controller on the window.
Now looking quickly at those 2 projects, what you'll need to do is create a menu view controller with a tab bar view controller as the center view controller. Then set the menu view controller as the root view controller of the window. Here is a very rough example of how you might do this.
GTabBar *tabBarViewController = [[GTabBar alloc] initWithTabViewControllers:#[<Tab View Controller>] tabItems:#[<TabBarItems>] initialTab:0];
YourLeftSideBarMenuViewController *leftMenuViewController = [[YourLeftSideBarMenuViewController alloc] init];
YourRightSideBarMenuViewController *rightMenuViewController = [[YourRightSideBarMenuViewController alloc] init];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:tabBarViewController
leftMenuViewController:leftMenuViewController
rightMenuViewController:rightMenuViewController];
self.window.rootViewController = container;
Have a look at the basic demo included in the menu MFSideMenu project.
I'd also suggest reading up a bit on how UIKit works, so you understand the difference between a window, view, viewController etc...
Apple has a pretty detailed guide that will give you the basics: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AppDesignBasics/AppDesignBasics.html#//apple_ref/doc/uid/TP40007072-CH2-SW1
Related
I am interested in creating an app that starts with a menu which may possibly contain an options view, then steps from the menu view to a data-item selection view, then to a configuration view, and finally a result view that displays progress or changes. I want to have this process be repeatable like a loop, and have the user be able to jump backwards to a previous view if necessary. Jumping from view to view would of course be a user input / output with a button or something. FYI, I am using Xcode 5.1.1.
What would be the best approach to this? What kind of view controller is going to do the trick? I have heard a lot about navigation controllers, tables, etc.. but am having a hard time figuring out what to use in my case.
Below is a state-diagram similar to what I would like to do...
A UINavigationController should work great as your root view controller. It automatically includes a back button, and you can use the popToRootViewController method to return to the root of the navigation controller. You can set up a navigation controller as your root view controller from the applicationDidFinishLaunching method using this code.
MainMenuViewController *mainMenuViewController = [[MainMenuViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mainMenuViewController;
self.window.rootViewController = navController;
For more information take a look at apples UINavigationController programming guide https://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
Each of your other screens may use different types of view controllers depending on their specific needs. If you need to display a list of items, definitely look into a UITableView. Apple's documentation for a UITableViewController can be found here https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewController_Class/Reference/Reference.html
Can anyone tell me what the best way to do the following is in Xcode (iPhone).
I have a main navigation screen with some buttons on it. When the user clicks any of the buttons they are taken to a sub-navigation screen with more option buttons on it. Here they click whichever button and are taken to a list of options. Clicking on any list option will display a screen with some information to the user. Each one of these screen ( no matter what section of the app you're in) will look the same. Only text and images on these screens will change.
I have enclosed a diagram that might explain it better. What is the best way to handle this in Xcode? I have tried doing it all in Stroyboard as I'm new to Objective C but just the sheer amount of individual pages is slowing my machine down to a crawl. So a rethink is required.
I am also doing an Android version of this app and I'm using Fragments for this. Can anyone please help?
EDIT: Just got to my devel machine and this is what I have been doing so far. I realise now this is the complete wrong way to do it. I have created a view controller for each "screen" if you like.
So I just create one view controller for all "screen" of e.g. Individual Page as per diagram and then add the text dynamically depending on what screen is selected? Can anyone point me in the direction of a tutorial or what I need to be searching for? I have no idea where to start with this using Xcode.
If the elements of the view are the same (and only the actual text and images are changing), all you need to do in your storyboard is to create one view controller that will have all these ui elements, from code you can then set it up depending on the content that you want to display in it (depending on what the user clicked in the previous view controller).
EDIT:
Not sure why it was downvoted, but i'll be more clear. Clearly that one view controller is not ALL you need to do in the storyboard. It's all you need to do ON the storyboard related to all the elements called Page in the diagram. Then you would have to link it to a PageViewController class and to all the outlets related to configurable UI elements and in the code of your prepareForSegue: method from the Secondary Nav Screen View Controller you would have to configure it accordingly to what you want to show.
Here you can find a good beginner's tutorial, along with many other good tutorials. What you're probably missing is that you also need to tell the storyboard what class the view controller is and how to connect stuff like labels and imageviews to the actual code so that you can configure them appropriately.
I.E.
From what you're describing, it sounds like you want a UINavigationController as your app's window's rootViewController and to show your screens inside that. You want to create four controller classes:
HMMainScreenController
HMSecondaryScreenController
HMListScreenController
HMPageController
Hopefully it's obvious what would be in each. You'd set up your window in your app delegate like this:
HMMainScreenController *mainController = [[HMMainScreenController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mainController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
When the user taps a button in your main controller, you'd do this:
HMSecondaryScreenController *secondaryController = [[HMSecondaryScreenController alloc] init];
// configure it appropriately
[self.navigationController pushViewController:secondaryController];
and so on for your list and page controllers.
I'm creating a tour screen where a user would swipe left and right to show some instructional pages.
However I'm having issues in loading pushing the next view. I've created a UINavigationController as below in a handleSwipes method:
TourViewController2 *tourView2 = [[TourViewController2 alloc] initWithNibName:#"TourViewController2" bundle:nil];
UINavigationController* navigationController = [[UINavigationController alloc] init];
[navigationController pushViewController:tourView2 animated:YES];
Any ideas?
Thanks.
As Aniket Kote wrote, you have to not only create UINavigationController, but also make it rootViewController in you application. After done this, UINavigationConroller became a main container and all others vies are placed inside it. For this reason you should not create UINavigationController every time you want to navigate through pages, but only one for all navigation path, eg. when you application in launching.
Next you can use this "global" navigation controller like
[self.navigationController pushViewController:tourView2 animated:YES];
Try this:
TourViewController2 *tourView2 = [[TourViewController2 alloc] initWithNibName:#"TourViewController2" bundle:nil];
UINavigationController* navigationController =[[UINavigationController alloc]initWithRootViewController:tourView2];
self.window.rootViewController=navigationController;
After reading your requirement, i will not go on your approach. I will suggest the use of "Page Control". As defined by Apple below :-
UIPageControl indicates the number of open pages in an application by
displaying a dot for each open page. The dot that corresponds to the
currently viewed page is highlighted. UIPageControl supports
navigation by sending the delegate an event when a user taps to the
right or to the left of the currently highlighted dot.
Hope this helps you !
I am a beginner in IOS field and I find it some what difficult to follow the old tutorials including videos which are not even 4-5 months old. The main reason is that I am working with xcode 4.2.1 and most of the tutorial is based on the earlier versions. So this is sort of letting me down to move with some examples which I want to work out.
The main problem is with MainWindow.xib file, where I found some nice tutorial and video of how one can manually reconstruct MainWindow.xib. I need to say I followed that and was good at recreating it. On the other hand it I have got a question, whatever new project I need to work on other than Empty Application, is it OK to create the MainWindow.xib file in the same way one created for the Empty Application, or it would be different for Tabbed Application or for some other application.
Can somebody throw some light on this!
Thanks
Maks
Following code for the creating the UItabbar.
In xcode 4.2.1 there is no any main.xib is created for that u need to apply the dynamically(code) thru create the tabbar and then call it.
-(void)applicationDidFinishLaunching:(UIApplication *)application {
// Add the tab bar controller's current view as a subview of the window
tabBarController.delegate=self;
tabBarController=[[UITabBarController alloc] init];
mainDashBoard=[[DashBoard alloc] initWithNibName:#"DashBoard" bundle:nil];
mainSearchView=[[SearchView alloc] initWithNibName:#"SearchView" bundle:nil];
mainMoreView=[[MoreView alloc] initWithNibName:#"MoreView" bundle:nil];
UINavigationController *nvCtr0=[[[UINavigationController alloc] init] autorelease];
UINavigationController *nvCtr1=[[[UINavigationController alloc] initWithRootViewController:mainDashBoard] autorelease];
UINavigationController *nvCtr2=[[[UINavigationController alloc] initWithRootViewController:mainSearchView] autorelease];
UINavigationController *nvCtr3=[[[UINavigationController alloc] initWithRootViewController:mainMoreView] autorelease];
UINavigationController *nvCtr4=[[[UINavigationController alloc] init] autorelease];//[[[UINavigationController alloc] initWithRootViewController:nil] autorelease];
tabBarController.viewControllers=[NSArray arrayWithObjects:nvCtr0,nvCtr1,nvCtr2,nvCtr3,nvCtr4,nil];
nvCtr0.tabBarItem.enabled=NO;
nvCtr4.tabBarItem.enabled=NO;
[window tabBarController.view];
}
It may be helpful to implement your application
There are many ways to make an application with a tap bar. I prefer to create the tab bar controller in code and do the interfaces of the view controllers shown in the different tabs with xibs. But sometimes I find it more practical to create the interfaces completely in code.
I would alloc and init a UITabBarController in the AppDelegate and assign the view controllers I need to the tab bar controller. Then you have to assign the rootViewController of the window to the tab bar controller.
i'm starting developing a new iPhone application, the interfaces that i will implement contains a lot of that shaft :
I have actually two question, what the suitable template to use? Window or Navigation based application?
Second question : in the Navigation Based Application, the first view that appears when i run the app is the one that contains a UITableView as below, can i replace it by an Image (UIImageView)?
Yes, Navigation based app is what you are looking for here. And yes, you can replace the UITableView with a UIImageView. I tend to start any project with a Window based project, and here's a quick way of doing it using window based project:
Create a window based project
Create you first view controller
Then in you application delegate, in the method applicationDidFinishLaunching, create a navigation controller, set it's root view controller to the view controller you created in the last step, and set the mac controller as the root view controller of the window. Here's a sample code:
FirstVC firstVC = [[FirstVC alloc] initWithNibName:#"FirstVC" bundle:#"nil"];
UINavigationConroller *navVC = [[UINavigationController alloc] initWithRootViewController:firstVC];
[[self window] setRootViewController:firstVC];
If you want to use a Navigation based project, then simply at the initWithRootViewController, remove the view controller set up by the template and set it to your own view controller.