I implemented the SplitView in my app as follow.
AppDelegate.h
#property (nonatomic, strong) IBOutlet UISplitViewController *splitViewController;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
LeftsideViewController *masterViewController = [[LeftsideViewController alloc] initWithNibName:#"LeftsideViewController" bundle:nil] ;
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController] ;
HomeViewController *detailViewController = [[HomeViewController alloc] initWithNibName:#"HomeViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.homeViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init] ;
[self.splitViewController.view setBackgroundColor:[UIColor blackColor]];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers=[NSArray arrayWithObjects:masterNavigationController,detailNavigationController,nil];
self.window.rootViewController = self.splitViewController;
NSLog(#"VIEWs %#",[self.window subviews]);
[self.window makeKeyAndVisible];
return YES;
}
Problem
It is working fine in ios 6.
But in ios 7 it shows the some view which i did not included.
See my following image & the extra view is in Pink Color.
float systemversion=[[[UIDevice currentDevice]systemVersion]floatValue];
if(systemversion>=7.0f)
{
self.edgesForExtendedLayout=UIRectEdgeNone;
}
Try this code
Related
The title pretty much says it all. I'm trying to create an interface where after connecting with Facebook, the window loads up my HomeViewController (my initially selected UITabBarItem). Although, I do not want the UINavigationBar that comes through as I have set the HomeViewController as the LoginViewController's root view. I have different navigation bar items for each view, so defaulting to that one won't work. I have this code now.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.mainViewController = [[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.mainViewController];
self.window.rootViewController = self.navigationController;
}
Create your custom tabbar Class add it in appDelegate
appDelegate.m
self.tabBarVC = [[[TabBarVC alloc] init] autorelease];
self.navController = [[[UINavigationController alloc]initWithRootViewController:self.tabBarVC]autorelease];
self.window.rootViewController = self.navController;
TabBarVC.h
#import <UIKit/UIKit.h>
#interface TabBarVC : UITabBarController
#end
TabBarVC.m
#import "TabBarVC.h"
#import "ViewController1.h"
#import "ViewController2.h"
#implementation TabBarVC
- (void)viewDidLoad
{
[super viewDidLoad];
UIViewController *vc1 = [[UIViewController alloc] initWithNibName:#"ViewController1" bundle:nil];
UIViewController *vc2 = [[UIViewController alloc] initWithNibName:#"ViewController2" bundle:nil];
[self setViewControllers:[NSArray arrayWithObjects:vc1,vc2, nil]];
}
#end
After a good nights sleep, I was able to figure it out. Hopefully, this can help others out there!
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.tabBarController = [[UITabBarController alloc] init];
// Initialize view controllers
HomeViewController *homeViewController = [[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil];
ConnectViewController *connectViewController = [[ConnectViewController alloc] initWithNibName:#"ConnectViewController" bundle:nil];
PartyControlViewController *partyControlViewController = [[PartyControlViewController alloc] initWithNibName:#"PartyControlViewController" bundle:nil];
MeViewController *meViewController = [[MeViewController alloc] initWithNibName:#"MeViewController" bundle:nil];
MoreViewController *moreViewController = [[MoreViewController alloc] initWithNibName:#"MoreViewController" bundle:nil];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:homeViewController, connectViewController, partyControlViewController, meViewController, moreViewController, nil]];
// Customize Tab Bar
UITabBarItem *homeTab = [[UITabBarItem alloc] initWithTitle:#"Home" image:nil tag:0];
UITabBarItem *connectTab = [[UITabBarItem alloc] initWithTitle:#"Connect" image:nil tag:1];
UITabBarItem *partyControlTab = [[UITabBarItem alloc] initWithTitle:#"Party Control" image:nil tag:2];
UITabBarItem *meTab = [[UITabBarItem alloc] initWithTitle:#"Me" image:[UIImage imageNamed:#"person.png"] tag:3];
UITabBarItem *moreTab = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMore tag:4];
[homeViewController setTabBarItem:homeTab];
[connectViewController setTabBarItem:connectTab];
[partyControlViewController setTabBarItem:partyControlTab];
[meViewController setTabBarItem:meTab];
[moreViewController setTabBarItem:moreTab];
self.window.rootViewController = self.tabBarController;
}
I am learning Xcode and working for IOS developer as trainee. I am using Xcode 4.2 and Lion OS. My targeted OS will be ios 3+ version. Somebody told me that using storyboard gives the problem for older version. So i want to develop without using Storyboard for navigationController. Help me out, cause all the old tutorials does not help at all, cause there are lots of missmatch due to change in xcode version.
Help me please.
For creating a navigation controller, select a Single View Application for your project template. In the AppDelegate.h, create an instance of the UINavigationController. In the AppDelegate.m file, do this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
navigationController = [[UINavigationController alloc] initWithRootViewController:(UIViewController*)viewController];
[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
This will give the base as a navigation controller. You can add other views on this using
[self.navigationController pushViewController:newViewController animated:YES];
While you creating new project
there is check marks for use storyboard just remove it from there.then move ahead as you are moving before.
Add this to your AppDelegate, and play around with them. See what happens and you will learn.
#interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>{
}
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UITabBarController *tabBarController;
#end
//*****************************************//
.m file
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[Categories alloc] initWithNibName:#"Categories" bundle:nil];
UIViewController *viewController2 = [[Coupons alloc] initWithNibName:#"Coupons" bundle:nil];
UIViewController *viewController3 = [[Favourites alloc] initWithNibName:#"Favourites" bundle:nil];
UIViewController *viewController4 = [[AroundMe alloc] initWithNibName:#"AroundMe" bundle:nil];
viewController2.title = NSLocalizedString(#"Coupons", #"Coupons");
viewController2.tabBarItem.image = [UIImage imageNamed:#"coupons.png"];
viewController3.title = NSLocalizedString(#"Favourites", #"Favourites");
viewController3.tabBarItem.image = [UIImage imageNamed:#"favourites.png"];
// UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:viewController4];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController1,navController2, navController3, navController4, nil];
self.window.rootViewController = self.tabBarController;
Excuse if this problem is posted already..
I want to create combination of TabBar and NavigationBar programmatically using XCode 4.2 & iPhone SDK 5.0
It produces visual as expected..but when a TabBarItem is pressed(taped) to change to its corresponding view, it is producing error: [__NSCFString _tabBarItemClicked:]: unrecognized selector sent to instance
Here is the implementation of the AppDelegat
#import "ApplicationDelegat.h"
#import "BrightnessController.h"
#implementation ApplicationDelegat
#synthesize window;
//#synthesize bControl;
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
NSMutableArray *controllers = [NSMutableArray array];
UITabBarController *tbarController = [[UITabBarController alloc] init];
for (int i = 0; i <= 3; i++)
{
//self.bControl = [[BrightnessController alloc] initWithBrightness:i];
BrightnessController *bControl = [[BrightnessController alloc] initWithBrightness:i];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: /*self.bControl*/bControl];
nav.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[controllers addObject: nav];
//bControl.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"test" image:nil tag:i];
//tbarController.navigationController.delegate = self;
}
tbarController.viewControllers = controllers;
tbarController.customizableViewControllers = controllers;
tbarController.selectedIndex = 0;
tbarController.delegate = self;
// NSCFString
//tabBarItem
// Set up the window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:tbarController.view];
[self.window makeKeyAndVisible];
}
#end
I don't know why it happens and how to recover it..
Somebody help me.
If more detail is required, I can provide the source code...
Thanks in advance.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController; 7:20
switch(mytabbar.selectedIndex)
{
case 0:
[imageView1 setImage:[UIImage imageNamed:#"Tab1_sel.png"]];
[imageView2 setImage:[UIImage imageNamed:#"Tab2.png"]];
[imageView3 setImage:[UIImage imageNamed:#"Tab3.png"]];
[imageView4 setImage:[UIImage imageNamed:#"Tab4.png"]];
[imageView5 setImage:[UIImage imageNamed:#"Tab5.png"]];
break;
case 1:
you can use this method and change on each tabbar click index
Two issues I see...
You assign the view of the tabBarController as a subView of the window. This is incorrect. You need to set the rootViewController of the window to be the tBarController.
Are you implementing the tab bar's delegate method tabBar:didSelectViewController:? Your error message says you're trying to send a tabBar-related method to an NSString. I suspect it's due in part to point (1). Try:
self.window.rootViewController = self.tBarController;
I typically prefer creating another tabbarview class that handles all the different view controllers, in which case, the app delegate will look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *viewController = [[ViewController alloc] init];
self.window.rootViewController = viewController.myTabBarController;
[self.window makeKeyAndVisible];
return;
}
And in ViewController I do this:
Header file:
#interface ViewController : UIViewController {
IBOutlet UITabBarController *myTabBarController;
}
#property (nonatomic, retain) IBOutlet UITabBarController *myTabBarController;
And in the implementation file:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
exerciseViewController *viewController1 = [[exerciseViewController alloc] init];
viewController1.title = #"Exercise";
viewController1.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Exercise" image:[UIImage imageNamed:#"inbox.png"] tag:0];
UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:viewController1];
bookViewController *viewController2 = [[bookViewController alloc] init];
viewController2.title = #"Book";
viewController2.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Book" image:[UIImage imageNamed:#"inbox.png"] tag:1];
UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:viewController2];
askViewController *viewController3 = [[askViewController alloc] init];
viewController3.title = #"Ask";
viewController3.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Ask" image:[UIImage imageNamed:#"inbox.png"] tag:2];
UINavigationController *thirdNavController = [[UINavigationController alloc]initWithRootViewController:viewController3];
workshopViewController *viewController4 = [[workshopViewController alloc] init];
viewController4.title = #"Workshop";
viewController4.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Workshop" image:[UIImage imageNamed:#"inbox.png"] tag:3];
UINavigationController *fourthNavController = [[UINavigationController alloc]initWithRootViewController:viewController4];
myTabBarController = [[UITabBarController alloc] init];
myTabBarController.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, thirdNavController, fourthNavController, nil];
}
return self;
}
This is just an example...and I think it's the right way to do that.
I have searched a lot about this topic and I can't get this code work. When I execute it, it only shows my test NSLog but the code to go from one view to another doesn't do anything. Here you have the following code:
//FirstViewController.h
#import <UIKit/UIKit.h>
#import "StationDetailsViewController.h"
#interface FirstViewController : UIViewController{
NSArray *ListaEstaciones;
NSArray *ListaID;
}
#property (nonatomic, retain) NSArray *ListaEstaciones;
#property (nonatomic, retain) NSArray *ListaID;
#end
//FirstViewController.m
#import "FirstViewController.h"
#import "StationDetailsViewController.h"
#implementation FirstViewController
#synthesize ListaEstaciones;
#synthesize ListaID;
//...
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"Pushing...");
StationDetailsViewController *controller = [[StationDetailsViewController alloc] initWithNibName:#"StationDetailsViewController" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
}
#end
I have tried lots of tutorials and my book but I don't know what is wrong. Thanks a lot, guys.
EDIT: Reading your answers I found that the error is on AppDelegate.m where rootViewController is defined.
//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
I don't know what to edit here to make this:
[[self navigationController] pushViewController:controller animated:YES];
work properly.
i think the problem is in [self navigationController] .. put a break point on this line of code and probaly you will find its value = nil cuz of that you are not having your detail controller .. you could solve this like that UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:yourMainViewControllerInstance];
This The appDelegate Code :
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *firstViewController = [[[FirstViewController alloc] initWithNibName:#"FBConFirstViewController" bundle:nil] autorelease];
UIViewController *secondViewController = [[[SecondViewController alloc] initWithNibName:#"FBConSecondViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:firstViewController]autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav, secondViewController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
I guess there is some problem either with datasource and delegate settings or your navigation controller.
Check this tutorial UITableView Tutorial
This might be helpful to you.
Enjoy Coding :)
can we use UITab bar controller in view base application thank you
Yes you can.
you can look at the "TheElements" example that apple provides.
you can find it here:
https://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.html
look at the app delegate.
its very strait forward example.
for you request i tried to make a simple example:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self setupPortraitUserInterface];
return YES;
}
- (UINavigationController *)AchievementsControllerWrappingViewController:(NSInteger*)tabIndex{
switch(tabIndex){
case 0:
FirstViewController *theViewController;
theViewController = [[FirstViewController alloc] init];
break;
case 1:
SecondViewController *theViewController;
theViewController = [[SecondViewController alloc] init];
break;
}
UINavigationController *theNavigationController;
theNavigationController = [[UINavigationController alloc] initWithRootViewController:theViewController];
[theViewController release];
return theNavigationController;
}
- (void)setupPortraitUserInterface {
UINavigationController *localNavigationController;
UIWindow *localWindow;
localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = localWindow;
[localWindow release];
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:2];
for(int i=0;i<2;i++){
localNavigationController = [self AchievementsControllerWrappingViewController:i];
[localViewControllersArray addObject:localNavigationController];
[localNavigationController release];
}
tabBarController.viewControllers = localViewControllersArray;
[localViewControllersArray release];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}
i am not next to xCode and i did it with text edit, so please check it when you use it.
shani
Yes we can..
For that you have to create UITabBarViewController and its Object then refrence it with you Application..like :
in your AppDelegate.h
#interface youAppDelegate.h : UIApplicationDelegate {
UIWindow *window;
YourViewController *viewController;
// Declare Your TabBarController Here
UITabBarController *tabBar;
}
#property (nonautomic, retain) IBOutlet UIWindow *window;
#property (nonautomic, retain) IBOutlet TabBarViewController *tabBar;
#end
in you implementation file's ApplicationDidFinish Launching add the following Code
viewController = [[YourViewController alloc] init];
[viewController addSubView:tabBar];
[self.window addSubView:viewController];
In interface builder you have to add the TabBarController to your MainWindow and relate it with the IBOutLet. Give what ever view you want to display in tabBar.
enjoy..