I try to implement a custom split view for an iPad application.
On the left side, I have a ViewController which contains the navigation.
The right side should contain a NavigationController with a navigation bar. When I initialize the NavigationController, I set the frame to the correct width:
FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
[firstView.view setFrame:CGRectMake(186, 0, 838, 748)];
[firstView.view setAutoresizesSubviews: NO];
UINavigationController navController = [[UINavigationController alloc] initWithRootViewController:firstView];
[navController.view setFrame:CGRectMake(186, 0, 838, 748)];
navController.navigationBar.topItem.title = #"Title";
But somewhere between viewWillAppear and viewDidAppear the frame.width from navController.view changes back to 1094 px. And so my title label is not correctly centered (within the visible area). Can I prevent the NavigationController from resizing? I already tried setAutoresizesSubviews: NO but this doesn't seem to work.
Related
I am putting a UINavigationController inside a container view like so (this in a full screen UIViewController subclass):
UIViewController *litteViewController = [[UIViewController alloc]initWithNibName:nil bundle:nil];
UINavigationController *littleNavigator = [[UINavigationController alloc]initWithRootViewController:litteViewController];
UIView *containerView = [[UIView alloc]initWithFrame:CGRectMake(100.0, 100.0, 250.0, 320.0)];
littleNavigator.view.frame = containerView.bounds;
[self addChildViewController:littleNavigator];
[containerView addSubview:littleNavigator.view];
[self.view addSubview:containerView];
[littleNavigator didMoveToParentViewController:self];
Now this works as expected and littleViewController appears in the rect I expect with a nav bar at top. Now let us say as a result of some interaction inside littleViewController something like this happens
-(void)someButtonAction:(id)sender{
UIViewController *secondLittleViewController = [[UIViewController alloc]initWithNibName:nil bundle:nil];
[self.navigationController presentModalViewController:secondLittleViewController animated:YES];
}
unfortunately this subsequent controller winds up being presented full screen. Now I've done exactly this before inside popoverControllers and splitViewControllers and they've behaved exactly as I want this to, a navigation stack is built within the little rectangle it was started in.
How can I build a navigation stack inside a container over in an arbitrary CGRect?
On iPhone and iPod touch, the presented view is always full screen. So you need change to pushViewController
Glad I can help
I have this code in AppDelegate
LoginViewController *loginVC = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
UINavigationController *navLogin = [[UINavigationController alloc] initWithRootViewController:loginVC];
navLogin.navigationBar.topItem.rightBarButtonItem = myRightBarButton;
self.window.rootViewController = navLogin;
I want to set the right bar button for this navigation controller where it won't change the button when pushing new viewcontrollers.
How can achive this ?
you had to set right bar button in each viewcontroller manually . you can use containerview then embed in in your Mainviewcontroller .
then from containerview -> embed segue to new navigationcontroller
adding view alignment should be like this
view {
->button
->containerview
}
like this,
then each pushed viewcontroller will have the right button automatically
you can set height width of viewcontroller 320 480 i.e all childviewcontroller get fullscreen
I started using UITabBarController and it is great.
The thing is I have a few views that aren't accessed from the UITabBar
(either presented modal programatically or we want to have a button on the top to jump to them)
The thing is that I want to retain the Tab bar visible in these views.
From my understanding mixing presentViewController and UITabBarController is problematic.
How can I do that? Can I have "hidden" tab bar elements I can reference programatically?
Just to clarify with an example:
Views A,B,C,D are in the tab bar - via the storyboard - everything is peachy.
I NEED to have views E and F clickable from the top navigation (please don't suggest a sliding TabBar or a multiple line UITabBar).
I could just jump to E and F but I want the UITabBar to still be visible so the user can jump from E to A for example.
Just use the good old UINavigationController for every tab and just use [self.navigationController pushViewController:A animated:YES];
That's how the setup looks in code:
SGTabBarViewController *rootVC = [[SGTabBarViewController alloc] init];
SGFirstTabViewController *firstVC = [[SGFirstTabViewController alloc] init];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:firstVC];
SGSecondTabViewController *secondVC = [[SGSecondTabViewController alloc] init];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondVC];
SGThirdTabViewController *thirdVC = [[SGThirdTabViewController alloc] init];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:thirdVC];
SGForuthTabViewController *fourhtVC = [[SGForuthTabViewController alloc] init];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:fourhtVC];
rootVC.viewControllers = #[navController1, navController2, navController3, navController4];
self.window.rootViewController = rootVC;
[self.window makeKeyAndVisible];
If you want your UITabBar visible on every VC you push just use hidesBottomBarWhenPushed = NO; on it.
However, there is no way to have UITabBar visible on views presented modally.
Having one main navigation controller in whole application and also one main tabbarcontroller , problem is that when i click om 'more' tab of tabbarcontroller at that time it's showing two navigation bars
to solve this problem i tried to hide my main navigation controllers navigationbar using following code :
self.tabbar.navigationController.navigationBarHidden =YES;
but doing this gives me unexpected result in the form of half navigationbar with half black background.
if any one knows the solution then please help me.
thanks in advance.
make viewController With separate UINavigationController,
put this code in Appdelegate
ViewController *a = [[ViewController alloc] initWithNibName:#"a" bundle:nil];
ViewController *b= [[CreateMeetingViewController alloc] initWithNibName:#"b" bundle:nil];
ViewController *c = [[SettingsViewController alloc] initWithNibName:#"c" bundle:nil];
UINavigationController *nav_1 = [[UINavigationController alloc] initWithRootViewController:a];
UINavigationController *nav_2 = [[UINavigationController alloc] initWithRootViewController:b];
UINavigationController *nav_3 = [[UINavigationController alloc] initWithRootViewController:c];
MainTabBar = [[UITabBarController alloc] init];
MainTabBar.delegate = self;
[MainTabBar setViewControllers:[NSArray arrayWithObjects:nav_1,nav_2,nav_3,nil]];
MainTabBar.view.frame=self.view.frame;
[self.view addSubview:MainTabBar.view];
You can check your .Xib you check the option Top Bar this should be 'None' in the identity inspector.
Write in viewWillAppear, i hope it will be helpful for you
[self.navigationController setNavigationBarHidden:YES animated:YES];
I would like to create a subview which loads notifications similar to Facebook in its iOS app. Does anyone know how to build that?
Thanks!
Something like that:
http://www.techarp.com/article/Apple/Facebook_Notifications/facebook.jpg
I suggest you to use a UIPopoverController.
UIViewController *viewController = [[UIViewController alloc] initWithNibName:#"UIViewControllerNibName" bundle:nil];
viewController.delegate = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navController];
navController.contentSizeForViewInPopover = CGSizeMake(400, 200);
viewController.contentSizeForViewInPopover = CGSizeMake(400, 200);
poopover.delegate = self;
CGRect rect = CGRectMake(0, 0, yourWidth, yourHeight);
[popover presentPopoverFromRect:locRect inView:parentView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:TRUE];
viewController is the UIViewController inside the popover, and there you can add, for example, a UITableView to show notifications. UIPopoverController is responsible of showing the popup view. Of course in presentPopoverFromRect: method you have to pass the frame the popover anchors to, the view in which present the popover, the arrow directions allowed and the animate flag in order to show the popover in an animated manner. Finally, with delegation you can communicate to the class that is allocing the popover (self.delegate = self).