Tabbar is not showing OR screen does not reconize touches - objective-c

i'm using this code for a tabbar, but the tabbar is not showing
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tabController = [[UITabBarController alloc] init];
UIViewController *viewController1 = [[UIViewController alloc] init];
UIViewController *viewController2 = [[UIViewController alloc] init];
UIViewController *viewController3 = [[UIViewController alloc] init];
UIViewController *viewController4 = [[UIViewController alloc] init];
tabController.viewControllers = [NSArray arrayWithObjects:viewController1,
viewController2,
viewController3,
viewController4, nil];
self.window.rootViewController = tabController;
UIViewController *rootController =
[[xTableViewController alloc]
initWithNibName:#"xTableViewController" bundle:nil];
navigationController = [[UINavigationController alloc]
initWithRootViewController:rootController];
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
When i remove this line:
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
The tabbar show's up but i cant 'touch' my screen (i cant touch my screen but the tabbar is 'touchable' because nothing is working, does anyone know how to display the tabbar on a normal way?

It seems like you are initializing the window twice. First with the UITabbarContorller and then with UINavigationController. Try
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tabController = [[UITabBarController alloc] init];
UIViewController *viewController1 = [[UIViewController alloc] init];
UIViewController *viewController2 = [[UIViewController alloc] init];
UIViewController *viewController3 = [[UIViewController alloc] init];
UIViewController *viewController4 = [[UIViewController alloc] init];
tabController.viewControllers = [NSArray arrayWithObjects:viewController1,
viewController2,
viewController3,
viewController4, nil];
self.window.rootViewController = tabController;
[self.window makeKeyAndVisible];
return YES;
}

Related

How to set view controller as root view in Cocoa?

I have an AppDelegate and mainWindow.xib. I created another viewController and called from AppDelegate and it is running good. Now my doubt is whether its possible to make the view controller as root with out adding it to mainWindow.xib. Whether its must to load our view with mainWindow.xib?
I am calling view controller like this
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self.view = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self.window.contentView addSubview:self.view.view];
self.view.view.frame = ((NSView*)self.window.contentView).bounds;
}
Try using
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.viewControllerObj = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.viewControllerObj;
[self.window makeKeyAndVisible];
return YES;
}
Try this:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self.view = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.view;
}
1.add this to your appdelegate.h
#property (strong, nonatomic) UIWindow *window;
2.add this to your appdelegate.m in didFinishLaunching method
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;

Add view in tab bar project - xcode

I have a x-code project made by tab bar. On AppDelegate.m I create three buttons for each view:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
UIViewController *viewController3=[[[ThirdViewController alloc]initWithNibName:#"ThirdViewController" bundle:nil]autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = #[viewController1, viewController2,viewController3];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
When I am on the first view I want to create a button that calls another view:
-(IBAction)btnPush{
[[self navigationController] pushViewController:newView animated:YES];
}
but when the new view comes up it covers the tab bar on the botton. How can I do to fix the problem?
Instead of Adding UIViewController in UITabBarController add UINavigationController as following
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
UIViewController *viewController3=[[[ThirdViewController alloc]initWithNibName:#"ThirdViewController" bundle:nil]autorelease];
Now add your ViewController to NavigationController
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
self.tabBarController.viewControllers = #[navController1, navController2,navController3];
It will add Navigation Controller in TabBarController

How to ECSlidingViewController without storyboard?

I want to use ECSlidingViewController in my iOS 4.3 applications.
And I wonder how to apply this library without storyboard?
PLZ, how to? this is my code, but iOS simulator's screen is white only.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//self.window.backgroundColor = [UIColor whiteColor];
FrontViewController *frontViewController = [[FrontViewController alloc] initWithNibName:#"FrontViewController" bundle:nil];
RearViewController *rearViewController = [[RearViewController alloc] initWithNibName:#"RearViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
// create a DDMenuController setting the content as the root
//DDMenuController *menuController = [[DDMenuController alloc] initWithRootViewController:navigationController];
//menuController.leftViewController = rearViewController;
//RevealController *menuController = [[RevealController alloc] initWithFrontViewController:navigationController rearViewController:rearViewController];
ECSlidingViewController *slidingViewController = (ECSlidingViewController *)self.window.rootViewController;
slidingViewController.topViewController = navigationController;
slidingViewController.underLeftViewController = rearViewController;
self.window.rootViewController = slidingViewController;
[self.window makeKeyAndVisible];
return YES;
}
Here is your code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
FrontViewController *frontViewController = [[FrontViewController alloc] initWithNibName:#"FrontViewController" bundle:nil];
RearViewController *rearViewController = [[RearViewController alloc] initWithNibName:#"RearViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
ECSlidingViewController *slidingViewController = [[ECSlidingViewController alloc] init];
slidingViewController.topViewController = navigationController;
slidingViewController.underLeftViewController = rearViewController;
self.window.rootViewController = slidingViewController;
[self.window makeKeyAndVisible];
return YES;
}
ECSlidingViewController uses iOS5, Storyboard and ARC. To put efforts into reengineering this class, I suggest you choose other classes which are ready for lower iOS versions and not using Storyboard. Some similar examples are:
https://github.com/pkluz/ZUUIRevealController
https://github.com/mystcolor/JTRevealSidebarDemo
The primary issue in your code above is that the slidingViewController isn't being instantiated.
You need this line:
ECSlidingViewController *slidingViewController = [[ECSlidingViewController alloc] init];

How to fill the screen with DetailViewController

I created a project using Master-Detail Application template but i don't need a MasterView. So i deleted Masterview files and codes but this time when i rotate the Simulator/Device in the left side of my main screen a black area stays. I want to stretch my Detail view to fill all the scren but i have no idea how to do. Can anyone please help? Thanks in advance
Note: My app needen NavigationController, firstly i tried SingleView template, but i couldn't push views on that template so i created my app in Master-Detail Application template..
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
BNT_DetailViewController *detailViewController = [[[BNT_DetailViewController alloc] initWithNibName:#"BNT_DetailViewController" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
BNT_DetailViewController *detailViewController = [[[BNT_DetailViewController alloc] initWithNibName:#"BNT_DetailViewController" bundle:nil] autorelease];
navigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
This was the first appearance of the didFinishLaunchingWithOptions:of my ..AppDelegate.m but i changed it with below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
//define navigationController in ..AppDelegate.h
BNT_DetailViewController *detailViewController = [[[BNT_DetailViewController alloc] initWithNibName:#"BNT_DetailViewController" bundle:nil] autorelease];
navigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
I answered my own answer in case it may be helpful for someone who lives the same pains:)

UINavigationController inside of UITabBarController issues

Can someone point me in the right direction with how to set up a UINavigationController inside of a UITabBarController? I have a feeling I'm using initWithRootViewController wrong.
ViewController1 *viewController1 = [[[ViewController1 alloc] initWithNibName:#"ViewController1" bundle:nil] autorelease];
self.navController = [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease];
ViewController2 *viewController2 = [[[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil] autorelease];
ViewController3 *viewController3 = [[[ViewController3 alloc] initWithNibName:#"ViewController3" bundle:nil] autorelease];
ViewController4 *viewController4 = [[[ViewController4 alloc] initWithNibName:#"ViewController4" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
_tabBarController.viewControllers = [NSArray arrayWithObjects:navController, viewController2, viewController3, viewController4, nil];
self.tabBarController.delegate = self;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
Thanks for any tips guys.
In the AppDelegate, you put this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UINavigationController *navC1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
UINavigationController *navC2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
UIViewController *viewController3 = [[[FirstViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil] autorelease];
UINavigationController *navC3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
UIViewController *viewController4 = [[[SecondViewController alloc] initWithNibName:#"ForthViewController" bundle:nil] autorelease];
UINavigationController *navC4 = [[UINavigationController alloc] initWithRootViewController:viewController4];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navC1, navC2, navC4, navC4, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Hope that help (Sorry for the bad english :-) );