I want to show new contact page on button click I have written this code within action button
{
ABNewPersonViewController *abnewpersonviewcontroller = [[ABNewPersonViewController alloc] init];
[self.navigationController pushViewController:abnewpersonviewcontroller animated:YES];
[newPersonController release];
}
this code succesfully reach me to the new contact page but the problem is navigation bar not shown onto the new contact page in which i can save record and also have cancel button on it kindly tell me how I can display the navigation on new contact page when I click on action button
use this
ABNewPersonViewController *abnewpersonviewcontroller = [[ABNewPersonViewController alloc] init];
self.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:abnewpersonviewcontroller animated:YES];
[newPersonController release];
ABNewPersonViewController *picker =[ABNewPersonViewController new];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:picker];
picker.newPersonViewDelegate =self;
[self presentViewController:nc animated:YES completion:nil];
did you hide navigation bar in your application?
if yes, then you should unhide before moving to contact page........
thanks
Well you can add self.navigationController.navigationBarHidden = NO; to that pushed view controller in - (void)viewWillAppear:(BOOL)animated method to force it but it should show automatically if you didn't added extra UINavigationBar to your UINavigationController.
Related
I have a class, DisplayOptViewController, which is a subclass of UICollectionViewController.
I want to display this CollectionViewController when the user clicks a button in the Navigation Bar on my current page. I am able to load the CollectionView on button Click but the Navigation Bar is not coming. I want the user to be able to see a back button in the navigation Bar and clicking the button should take him back to the current page.
I tried to do this via storyboard as well as programmatically. When I try this via the Storyboard, the ViewController itself is not displayed and when I create the view controller object programmatically, I am not getting the Navigation Bar. Any idea how to to this?
I tried to add this code to my viewDidLoad method in DisplayOptViewController:
UINavigationBar *navBar=[[UINavigationBar alloc] init];
[[self navigationController] setNavigationBarHidden:NO animated:YES];
[self.navigationController.navigationBar addSubview:navBar];
But the Navigation Bar still didn't come. Kindly help.
update
I am loading the UICollectionView here
UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init];
[aFlowLayout setItemSize:CGSizeMake(140, 50)];
[aFlowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
DisplayOptViewController *vc=[[DisplayOptViewController alloc] initWithCollectionViewLayout:aFlowLayout];
[self presentViewController:vc animated:YES completion:nil];
You have a few things that i question,
[self.navigationController.navigationBar addSubview:navBar];
you are adding a navigation bar to a navigation bar.... do this instead
[self.navigationController setNavigationBar:navBar];
second
[self presentViewController:vc animated:YES completion:nil];
you are presenting the controller.... not pushing/poping it....
[self.navigationController pushViewController:vc animated:YES];
try that in when you do it programmatically
as for the storyboard maybe you don't have the segues set up correctly, or properties not set right or something... but i can't debug it like this
If you have a navigation based project, then you have to initialize the navigation controller in the app delegate itself. Try the code below to make the navigation bar visible,
In application didFinishLaunchingWithOptions method,
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[self viewController]];
[[self window] setRootViewController:navigationController];
[self.window makeKeyAndVisible];
return YES;
Now your navigation bar will appear.
Currently i am working in iPhone app, i have four screen like Login, A,B and c etc..
User enter the username and password field in login screen, then press login button
-(void)LoginButtonMethod
{
A *a = [[A alloc]init];
B *b = [[B alloc]init];
C *c = [[C alloc]init];
UINavigationController *navi1 = [[UINavigationController alloc] initWithRootViewController:a];
UINavigationController *navi2 = [[UINavigationController alloc] initWithRootViewController:b];
UINavigationController *navi3 = [[UINavigationController alloc] initWithRootViewController:c];
UITabBarController *TabBar = [[UITabBarController alloc] init];
TabBar.delegate = self;
TabBar.viewControllers = [NSArray arrayWithObjects:navi1, navi2, navi3, nil];
navi1.tabBarItem.title=#"A";
navi2.tabBarItem.title=#"B";
navi3.tabBarItem.title=#"C";
[self.navigationController pushViewController:TabBar animated:YES];
}
Then i have set navigationbar title for each class like A as facebook, b as yahoo, c as google.
Finally i run the application, tabbar title showing in A,B,C
Then i select 3rd tabbar item (C), at the time that tabar title change google.
i can't fix this, please help me.
Thanks in Advance
Apple in it's developer documentation states following:
"You never want to push a tab bar controller onto the navigation stack of a navigation controller. Doing so creates an unusual situation whereby the tab bar appears only while a specific view controller is at the top of the navigation stack. Tab bars are designed to be persistent, and so this transient approach can be confusing to users."
try presenting it
[self presentModalViewController:tabBar animated:YES];
You can push Tabbar to Controller By
Either
[self.navigationController pushViewController:tabBar animated:YES];
or
[self presentModalViewController:tabBar animated:YES];
Hope this will fix your problem
in this
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
Method of each view Controller put the following code..
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Comment" image:[UIImage imageNamed:#"Icon-AddComment.png"] tag:0];
self.navigationItem.title = #"Comment";
it Works
I am developing an e-com app for iPhone in which i need to open a view immediately when the user clicks on a button for the upcoming view, the data loads large images from server , to load images I am using a background thread .
Thank You
Simple, here's how to create a UIViewController and present it from within an IBAction.
- (IBAction)goToNextView:(id)sender
{
//if you are using xibs use this line
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"myXib" bundle:[NSBundle mainBundle]];
//if you are using storyboards use this line
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"myViewControllersID"];
//to present the controller modally use this
[self presentViewController:controller animated:NO completion:nil];
//or if you are pushing to this controller using a navigation controller use this
[self.navigationController pushViewController:controller animated:NO];
}
Be sure to pass animated NO so that the view is displayed immediately.
You need to make a button and then add its action like
-(IBAction)ButtonAction:(id)sender{
CalController *calculateView=[[CalController alloc] initWithNibName:#"CalController" bundle:nil];
[self.navigationController presentModalViewController:calculateView animated:NO];
}
You can use modal view controller for this
- (IBAction)showController:(id)sender {
SampleViewController *sampleView = [[SampleViewController alloc] init];
[self presentModalViewController:sampleView animated:YES];
}
Here it is the tutorial http://timneill.net/2010/09/modal-view-controller-example-part-1/
I need to implement the back button; (as in webpages, when you click the back button the screen will set focus to the previous screen).
I am not using a navigation control here, instead i want to do this using a Navigation bar and then adding a navigation button on it. Now when the user clicks on the navigation button the previous view should be displayed.
How should i do this.
My screen looks like this :
When i click on Hello, it should go to the previous screen.
Check out UINavigationController Class Regerence then try something like this:
- (void)pickerCancel {
[self dismissModalViewControllerAnimated:YES];
}
- (void)doSomething {
[myView.navigationItem setBackBarButtonItem:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(pickerCancel)] autorelease]];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:myView];
[navigation setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[navigation setDelegate:self];
[self presentModalViewController:navigation animated:YES];
[myView release];
[navigation release];
}
You really should use a UINavigationController as that is its entire purpose.
In my app there is requirement that..I have 6 buttons in a nib,
when I press any button a new nib will be loaded into the window according to the button pressed. problem is after loading the new nib If I want to come back to the previous nib (which is having all the buttons) how to add navigation controller?
what I am doing now is while loading the new nib when I pressed the button
objNewViewController = [[NewViewController alloc] initWithNibName:#"NewViewController" bundle:nil];
[self.navigationController pushViewController:objNewViewController animated:YES];
but by this way im not able to load the nib, it's not performing any operation?
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[NewViewController alloc] initWithNibName:#"NewViewController" bundle:nil]];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
And in NewViewController:
USe this to dismiss and get back to previous view.
[[self navigationController] dismissModalViewControllerAnimated:YES];
There is a template in Xcode for a navigation based app. It does everything you describe. Well, very close at least, only the AnotherViewController in -tableView:didSelectRowAtIndexPath: is commented out.