how to push views iphone? - ios

i'm new to iphone development and i need some guidance in pushing views. I have the following application scenario "press on button ->switch view (contains a table)->press on table cell ->switch view".
To switch when i press the button i use the following code :
MapView *screen = [[MapView alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:screen animated:YES];
[screen release];
Then to push another view i want to use this code (but it does not work - and im asking why?)
Newclass *nextController = [[Newclass alloc] initWithItem:theItem];
[self.navigationController pushViewController:nextController animated:YES];
[nextController release];

You want to push this view from your MapView? Looks like you don't have a UINavigationController which is needed to push view controllers like that.
Update the first part of your code to put the MapView inside UINavigationController, than you can push other views onto it with that second part of code you have.
MapView *screen = [[MapView alloc] initWithNibName:nil bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:screen]; // this puts the MapView onto navigation controller
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; // you will present the navController instead of screen so change it's modalTransitionStyle
[self presentModalViewController:navController animated:YES]; // present it
[screen release];
[navController release]; // don't forget to release

Related

How to present view bottom to top when using navigationController

ViewController *viewController = [[ViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];
With above code, the "ViewController" moves from right-to-left.
Is it possible to present "ViewController" bottom-to-top?
I tried but it does not work.
viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
I created "Navigation Controller" as follows
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
[navController setNavigationBarHidden:YES];
Most bottom-to-top animations of a new view controller involve the presentation of the view controller using:
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
Your code involves a navigation stack push, which is usually a right-to-left animation.
If you want to present a view controller then on button click event you have to write following code.
I hope this will work for you :
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:NSStringFromClass([DetailViewController class]) bundle:nil];
[self.navigationController presentViewController:detailViewController animated:YES completion:nil];

iOS - how to set a navigation bar item in view controller?

I'm new to Objective-C and I want to add a UINavigationBar on my CatrgoryBIDViewController. I have proceed UIButton in InstructionBIDViewController.m file that should navigate to CatrgoryBIDViewController. Here is the function code:
- (IBAction)proceed:(id)sender {
viewControllercat =
[[CatrgoryBIDViewController alloc]
initWithNibName:#"CatrgoryBIDViewController"
bundle:nil];
UINavigationController *nav =
[[UINavigationController alloc]
initWithRootViewController:self.viewControllercat];
//[self.navigationController pushViewController:viewControllercat animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
But it is not setting the UINavigationBar.
You should read the documentation here to understand the way a NavigationController is working. For your case:
If your current ViewController (where your proceed-method is implemented) has a NavigationController (is child of it), you can push another ViewController onto the stack of that NavigationController with
[self.navigationController pushViewController:viewControllercat animated:YES];
In this case you do not need to initialize another NavigationController, but in your CatrgoryBIDViewController in viewWillAppear you need to make the NavigationBar visible if it was not before already with
[self.navigationController setNavigationBarHidden:NO animated:YES];
If your current ViewController does not have a NavigationController, you can not push another ViewController on top of it and can not show the NavigationBar of it (although you can create your own NavigationBar and add it to the View of the ViewController, but without the usual Navigation-behaviour embedded).
If you open your ViewController programmatically (e. g. from the AppDelegate) you are correct to do so by your call:
viewControllercat = [[CatrgoryBIDViewController alloc] initWithNibName:#"CatrgoryBIDViewController" bundle:nil];
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:self.viewControllercat];
My apologies - After having reread your question, I am going to tweak my answer some.
-(IBAction)proceed:(id)sender
{
viewControllercat = [[CatrgoryBIDViewController alloc] init];
UINavigationController * nc =
[[UINavigationController alloc] initWithRootViewController:vc];
// We now need to display your detail view but cannot push it.
// So display modally
[self presentViewController:nc animated:YES completion:Nil];
}
The above should result in your DetailViewController - CategoryBIDViewController being displayed on top of your InstructionBIDViewController and it should have a UINavigationController in it.

Push a View from popOver in ipad

I open a popOver with a view(DetailView) in a view(MapView). it works fine.
But in my detail view has a button(feedback).so i want to push the another view(feedbackform)on btton clicked.
I tried but nothing is Happened.
Can i push the view inside the popover?
My code is as follow:
// MapView.m
detailsView *popUp=[[detailsView alloc] initWithNibName:#"detailsView_ipad" bundle:nil];
popView = [[UIPopoverController alloc]initWithContentViewController:popUp];
popView.delegate =self;
[popView setPopoverContentSize:CGSizeMake(600, 500)];
[popView presentPopoverFromRect:control.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
//Detailview.m
-(IBAction)openFeedbackForm:(id)sender {
fbView = [[deatailsFeedback alloc]
initWithNibName:#"deatailsFeedback_ipad" bundle:nil];
[self.navigationController pushViewController:fbView animated:YES];
}
To achieve this your detailsView should be a Navigation controller with a root controller to the original detailsView.
This way when you pop the navigationController, you can perform push from your detailsView and that would only affect the popOver view
detailsView *popUpView=[[detailsView alloc] initWithNibName:#"detailsView_ipad" bundle:nil];
UINavigationController *popUpNavController = [[UINavigationController alloc] initWithRootViewController:popUpView];
popView = [[UIPopoverController alloc]initWithContentViewController:popUpNavController];
popView.delegate =self;
[popView setPopoverContentSize:CGSizeMake(600, 500)];
[popView presentPopoverFromRect:control.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
//Detailview.m
-(IBAction)openFeedbackForm:(id)sender {
fbView = [[deatailsFeedback alloc]
initWithNibName:#"deatailsFeedback_ipad" bundle:nil];
[self.navigationController pushViewController:fbView animated:YES];
}
If I understand your code correctly, openFeedForm IBAction method is in Detailview.m?
Meaning the first part of the code is in a different class than the one at the bottom?
If so, since Detailview itself is not in a navigationController, it will not push anything to its non-existant navigation controller.
What you want to do is have MapView push the new view in its navigationController.
Side note: since you are setting the delegate of the popUp in MapView as (self) the IBAction method should be defined in MapView
(This is assuming my first statement about understanding your code is correct)

how to add uinavigationcontroller as a second view not as rootviewcontroller

i know how to add uinavigationcontroller as root view and also how to push view in uinavigationcontroller.
What i am confused in the first view which is a root view is a simple view with button when this button is tapped it will show second view.
I want this second view as uinavigationview.
any ideas how to do it, i tried to search for the solution but didn't get any nor any similar question is asked before.
basically i am trying to work without interface builder to learn things in depth.
assuming you are presenting the 2nd view controller modally
instead of
UIViewController *vc = [[[UIViewController alloc] init] autorelease];
[self presentModalViewController:vc animated:YES];
do:
UIViewController *vc = [[[UIViewController alloc] init] autorelease];
UINavigationController *nc = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:nc animated:YES];

adding an UINavigationController to a UIControllerView

i was searching this whole afternoon in hope of solution but i didn't manage to find anything helping me solve the problem.
The problem is, i have no intention of using UINavigationController until a button gets taped, and after that i would like to present view controller containing a navigationcontroller, or reverse, modally. in my search i came across this solution:
MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:#"MyExample" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:navController animated:YES];
which i then used it in my code and found out it is not working, to make sure i started a practice project from viewbased project templet and added this to the first view controller
- (IBAction) buttonGotPreseed{
testino *testController = [[testino alloc] initWithNibName:#"testino" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:testController];
testController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:testController animated:YES];
[nav release];
[testController release];
}
didn't work also, im not seeing the navigation bar up there
any help would be greatly appreciated
You're pushing the root view controller, not the navigation controller itself. Line 5 should be:
[self presentModalViewController:nav animated:YES];

Resources