UINavigationController not displaying - ios

I am new to IOS dev so I'm sure the answer is simple but my ignorance makes it hard to find the answers online. I'm trying to use a UINavigationController to switch between views. Thus far I have been succesfully displaying the first view with the following code.
FLInitialMapViewController *control = [[FLInitialMapViewController alloc] init];
self.window.rootViewController = control;
I then wrote the code to add the navigation controller but when I run it I see mostly a black screen with a gray bar at the top of it. Here's the code
FLInitialMapViewController *control = [[FLInitialMapViewController alloc] init];
_navController = [[UINavigationController alloc] initWithRootViewController:control];
self.window.rootViewController = _navController;
Here is the complete code for AppDelegate.m in 'didFinishLaunchingWithOptions':
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FLInitialMapViewController *control = [[FLInitialMapViewController alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController: control];
[self.navController setNavigationBarHidden:YES];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
return YES;
Interestingly, the gray bar near the top is slightly translucent and I can see some of my UI elements underneath it.
EDIT: I removed the top bar and now I see the following!
This is what should be seen.

I have added navigation bar setup for your convenience. Try this in your AppDelegate.m under didFinishLaunchingWithOptions: method -
FLInitialMapViewController * control = [FLInitialMapViewController new];
UINavigationController *myNav = [[UINavigationController alloc] initWithRootViewController: control];
self.window.rootViewController = myNav;
// Setup navigation bar programmatically
UINavigationBar *navigationBar = myNav.navigationBar;
navigationBar.barTintColor = [UIColor orangeColor];
navigationBar.barStyle = UIBarStyleBlackOpaque;
// Boiler plate code from AppDelegate
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

Related

is there something wrong of iOS simulator's 'color offscreen-rendered' function?

i want to see which view is offscreen-rendered in my app.So i use the iOS simulator's 'color offscreen-rendered' function,it can color those offscreen-rendered view by yellow color.But after the app launched,the whole screen is colored by yellow and i don't believe it.
Then i try my test code like:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[UITabBarController alloc] init];
// self.window.rootViewController = [[UINavigationController alloc] init];
// self.window.rootViewController = [[UIViewController alloc] init];
[self.window makeKeyWindow];
}
As you can see above,i simply set the window's rootViewController three times different by orginal controllers: 'UITabBarController','UINavigationController' and 'UIViewController'.
Guess what?
Only the 'UIViewController' is not whole screen colored!!!
So anyOne knows why the orginal rootViewController and UINavigationController will occur the whole screen offscreen-render??????
It's because default translucent value of UITabBar and UINavigationBar are YES.
You should check Apple documents for UINavigationBar.translucent and UITabBar.translucent for more information.
A small demo by creating a UINavigationController with a red background root view controller, we can compare the difference when translucent is YES and NO.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
UIViewController* viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [UIColor redColor];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
// nav.navigationBar.translucent = NO;
self.window.rootViewController = nav;
[self.window makeKeyWindow];
return YES;
}
By default, translucent is YES. So you can see background of UINavigationBar has a little red.
Color offscreen-rendered
But when we set translucent to NO. No more red in background of UINavigationBar.
Color offscreen-rendered
We have transparent here so that's why screen is colored. You can try similar thing with translucent of UITabBar.
To avoid offscreen-rendered with UINavigationController and UITabBarController, you should set this property to NO.

MMDrawerController configure left menu

My Left menu displace center view. It looks worse than if Left Menu cover center view.
explanation
How i can configure it?
//MMDrawerController
ViewController * centerViewController = [[ViewController alloc] init];
UINavigationController *centerNavigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
ViewController *leftViewController = [[ViewController alloc] init];
UINavigationController *leftNavigationController = [[UINavigationController alloc] initWithRootViewController:leftViewController];
_drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerNavigationController leftDrawerViewController:leftNavigationController];
[leftNavigationController setNavigationBarHidden:YES];
[centerNavigationController setNavigationBarHidden:YES];
[_drawerController setMaximumLeftDrawerWidth:300.0];
[_drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIColor * tintColor = [UIColor colorWithRed:29.0/255.0
green:173.0/255.0
blue:234.0/255.0
alpha:1.0];
[self.window setTintColor:tintColor];
[self.window setRootViewController:_drawerController];
[self.window makeKeyAndVisible];

UITabBar Functionality

TabBar should not be enable any of tabs untill user clicked on any one of tab,
Below is the code I write to display tab bar, But the problem by defaultly it is showing the first tab.
- (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];
[self.window makeKeyAndVisible];
PeopleViewController *peopleViewController = [[PeopleViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:peopleViewController];
[peopleViewController setTitle:#"People"];
EventsViewController *eventsViewController = [[EventsViewController alloc] init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:eventsViewController];
[eventsViewController setTitle:#"Events"];
ActiveViewController *activeViewController = [[ActiveViewController alloc] init];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:activeViewController];
[activeViewController setTitle:#"Active"];
MoreViewController *moreViewController = [[MoreViewController alloc] init];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:moreViewController];
[moreViewController setTitle:#"More"];
NSArray *arrViewControllers = [[NSArray alloc] initWithObjects:nav1,nav2,nav3,nav4, nil];
[tabBarController setViewControllers:arrViewControllers];
[self.window addSubview:tabBarController.view];
return YES;
}
Create an IBOutlet for the tab bar (e.g. theTabBar) and use following code:
[theTabBar setSelectedItem:nil];
This is default behavior of UITabBarController, by default first tab is selected.
You have the option to make some other tab to be selected at first instance, but cannot change the default selected to null.
[tabBarController setSelectedIndex:0];
By default selected index is 0, this is first tab, you can change it as per your requirement to 1,2,3.

Can't pop iOS viewController. Not sure, but I think it's something with the Navigation Controller

I'm having trouble trying to pop a view
App Delegate
#implementation MAAppDelegate
#synthesize navController;
#synthesize detailViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Init the navController for the Master Detail View of the grade cells
UINavigationController *navController = [[UINavigationController alloc] init];
detailViewController = [[UIViewController alloc] init]; //step6
navController = [[UINavigationController alloc] initWithRootViewController:[[MAController alloc] init]]; //step7
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = navController; //step8
[self.window makeKeyAndVisible];
// Set MAController as rootViewController
//self.window.rootViewController = [[MAController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// Use the insanely cool TSMessages to show network alerts
[TSMessage setDefaultViewController: self.window.rootViewController];
return YES;
}
First part of viewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.navigationController setNavigationBarHidden:YES];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:#"Home" style:UIBarButtonItemStyleBordered target:self action:#selector(home:)];
self.navigationItem.leftBarButtonItem=newBackButton;
Later, when I change the viewController
NSLog(#"Opened progress report");
UIViewController *detailViewControl = [[UIViewController alloc] init];
// Set progress report as the view controller
[self.navigationController pushViewController:detailViewControl animated:YES];
UIImage *background = [UIImage imageNamed:#"bg"];
// Add static image bg
self.backgroundImageView = [[UIImageView alloc] initWithImage:background];
self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:self.backgroundImageView];
// Add blurred layer to image when tableView goes in front of it
self.blurredImageView = [[UIImageView alloc] init];
self.blurredImageView.contentMode = UIViewContentModeScaleAspectFill;
self.blurredImageView.alpha = 0;
[self.blurredImageView setImageToBlur:background blurRadius:10 completionBlock:nil];
[self.view addSubview:self.blurredImageView];
[self.navigationController setNavigationBarHidden:NO];
So I don't understand why that when I do this, a selector from the button (that I know fires, because I get Righthtere in my log):
-(void)home:(UIBarButtonItem *)sender {
NSLog(#"Righthtere");
// Set progress report as the view controller
[self.navigationController popToViewController:self animated:YES];
}
It doesn't go back to the initial view controller.
You seem to be confusing popToViewController and popViewControllerAnimated. popViewControllerAnimated removes the current view from the stack and brings the new stack top the active view controller. popToViewController pops the stack until the listed view controller is on top of the stack.
Since you are calling popToViewController with self, it will look and see that the requested view controller is already on top of the stack and do nothing. If you wish to go back one view controller then your call should be.
[self.navigationController popViewControllerAnimated:YES];
I use the below code to pop the previous viewcontroller in iOS 8.
[self presentModalViewController:viewcontroller animated:YES];

TabBarController and NavigationController

I am making an application but I'm still a beginner and I'm trying to get used to the RootViewController and how it should be set.
At the beginning my application launches, I want there to be a View which is not in my tabBarController (which is set to be my rootViewController).
What I am trying to ask is, Can I have another view which is outside my UITabBarController launch first without it being in the tabBarController's items list?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
FacebookFeedViewController *facebookClass = [[FacebookFeedViewController alloc] initWithNibName:#"FacebookFeedViewController" bundle:nil];
TwitterFeedViewController *twitterClass = [[TwitterFeedViewController alloc] initWithNibName:#"TwitterFeedViewController" bundle:nil];
LinkedInFeedViewController *linkClass = [[LinkedInFeedViewController alloc] initWithNibName:#"LinkedInFeedViewController" bundle:nil];
FTLFullFeedViewController *masterClass = [[FTLFullFeedViewController alloc] initWithNibName:#"FTLFullFeedViewController" bundle:nil];
/// tab button title
facebookClass.title = #"Facebook";
twitterClass.title = #"Twitter";
linkClass.title=#"LinkedIn";
masterClass.title=#"FTL";
// tab button Images
facebookClass.tabBarItem.image = [UIImage imageNamed:#"facebook_32"];
twitterClass.tabBarItem.image = [UIImage imageNamed:#"twitter_32"];
WelcomeViewController *welcomeClass= [[WelcomeViewController alloc] initWithNibName:#"WelcomeViewController" bundle:nil];
navController = [[ UINavigationController alloc] initWithRootViewController:welcomeClass];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:facebookClass];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:twitterClass];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:linkClass];
UINavigationController *navController5 = [[UINavigationController alloc] initWithRootViewController:masterClass];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController,navController5,navController2,navController3,navController4,nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
I know you already selected an answer but all that's doing is pushing a UITabBar view on top of an existing view, not creating a new UITabBarController view. Based on our brief conversation (latest XCode, no StoryBoards, using XIBs) you're going to want to create a xib as a UITabBarController then push it into view...
View *view = [[View alloc] initWithNibName:#"myUITabBarXIB" bundle:nil];
view.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: view animated:YES];
This will present your XIB file but not on top of the existing view controller when the desired action takes place.
yes! ofcourse you do.
[self.view addsubview:yourTabbar.view];
Hope this will help you.

Resources