How can i go from a mapview to a simple view - objective-c

I am working on an app in which the starting point is a map and it has a button too. What i want is that if user clicks the button it will take him to another view which just have two or three buttons or other elements.
Please provide me with detail answer so that i would be able to do it.
Thanks in advance, i would really appreciate it.

just put this code inside your button action and change it your needs
YourViewControler *yourViewControler = [[YourViewControler alloc] initWithNibName :#"YourViewControler" bundle:nil];
[self.navigationController pushViewController:yourViewControler animated:NO];
[yourViewControler release];
and you can add anything in YourViewControler.
I hope it will help you.

That could be achieved in a lot of ways. For example you could use a controller for each view you need and switch between them with the use of a UINavigationController. Use the map controller as the root of the navigation controller, then when the user presses the button just call pushViewController:animated:

Related

Changing the Title of the Back Button in Objective-C

This may be a silly question, but how would I go about changing the 'back' button of the navigation controller to simply say 'Back' every time I push to a different ViewController?
For example, if I'm going from the Master to the Detail then it will have: "< Master" as the back button text. Can I change it easily to "< Back" without messing around too much? (It's just I have quite a few segues going and if I have to replace the button manually I'm probably going to screw up something else...)
All help is appreciated. Thanks :)
You need to assign a backBarButtonItem to the current navigation item before pushing another. Navigation items are pushed when view controllers are pushed.
So something like this:
self.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"Back", #"") style:UIBarButtonItemStylePlain target:nil action:NULL];
[self.navigationController pushViewController:next];
The target and action of the bar button item are not required, as only the title is used.
You can set backBarButtonItem once in viewDidLoad of your view controller.
It automatically grabs the title of the previous view controller as long as the title is short enough to fit into the button. To override this behavior, you can provide your own UIBarButtonItem for the backBarButtonItem property. (Just create a basic push button and it should work IIRC.)

Home button in drill down app

I am writing an iOS app that has a 3-4 level of drill down. In the 2nd, 3rd... and so on views, I want to add a home button on the nab bar, which once pressed takes you back to the root view controller, i.e. the first screen.
I have added a button using storyboard and simply want to implement the - (void) homeButtonpressed:(id)sender function so that my first view is displayed.
Also, if this is some kind of a built in functionality for this (like there is for back button), then that would be great, as I will need to write this piece of code in all my child views.
Can somebody help me with this?
Thanks!
You can pop to rootview by using the following code
[self.navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex: 0] animated: YES];
or
[self.navigationController popToRootViewControllerAnimated:YES];
Make an array of your view controllers
Pops all the view controllers on the stack except the root view controller and updates the display.
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
[self.navController popToRootViewControllerAnimated:(BOOL)animated];

How to Refer to the Current View Controller in the Code

I'm a new iOS developer with a simple question: I want to programmatically move from one view controller to the next, how do I write this code?
So far I have:
UINavigationController *navigationController;
navigationController = [[UINavigationController alloc] init];
[self.view addSubview:navigationController.view];
[navigationController pushViewController:viewController animated:NO];
I'm not even sure if this will work, ultimately, but my main question is "viewController" in line 4. The program doesn't know what that is. It is the name of my current view controller, but how do I set it up so that it knows what I mean by viewController?
As an aside, the above is part of an if/else statement that occurs and is connected to the NSUserDefaults class to make it such that the view controller I am referring to only loads if terms and conditions have not previously been accepted. Will that work? Thanks.
First the simple answer: pass self when you want to pass the "current" object.
The more important consideration is: is that nav controller on screen? It's likely that your code won't do much unless you use a navigation controller which is (probably) the window's root view controller.
This is fairly easy to setup in your storyboard ("embed in"->"navigation controller") and then you don't need to instantiate it in code, you simply use self.navigationController (usually).
Normally, you would instantiate viewController just before you push it, so the program will know what it is. And, sure, you can have an if statement, and push this new view controller based on how the if statement evaluates.
I'm not sure about the code you wrote -- whether that's right depends on the structure of your app, and where you're doing this. Often, the navigation controller is made the root view controller of the window, and you set the navigation controller with a root view controller of its own when you create it

UIViewControllers problems

Hi there and thank you in advice for your help. I have a really strange problem while working with ViewControllers in Xcode4. First of all I have to say that I'm not using storyboards and I prefer to create any UI element programmatically. So I've set a UIButton and I want that, when pressed, it brings me to a new view controller. This is the code I'm using for a button:
-(void)settingsAndExportHandle:(UIButton *)buttonSender {
SettingsViewController* settingView = [[SettingsViewController alloc] initWithNibName:#"SettingsViewController" bundle:nil];
settingView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:settingView animated:YES];
}
This buttons is initialized and allocated in the viewDidLoad method of the RootViewController. I want to switch to the other view controller (in this case SettingsViewController) when I press the button.
The strange thing is that when I press the button, the animation that flips the controllers goes well, but when it finishes I obtain the EXACT same things that I had on the RootViewControllers (same custom views, same buttons, same all!). The question is: what I'm missing?? I have to say that I use ARC (automatic reference counting) so I can't release or dealloc the views and buttons I've created on my RootViewController.
Any help will be appreciated. Thank you all!
Pushing and and modally presenting view controllers does not deallocate the view controller that presented them. It simply adds the additional view controller to the stack. You'll need to implement a callback method so that when the user hits the button to flip back to root view controller, your settings view controller lets the root view controller know what's about to happen so you can call a method you've written to reset the interface back to whatever state you need it at. You may also be able to use viewWillAppear: but that's a little messy.
However, according to the Apple Human Interface Guidelines, the user expects that when they push a view controller or modally present it, the view controller they were on will save state and be exactly the way they left it when they came back. It's disconcerting and annoying when state is not preserved while in a navigation controller context. It is especially annoying when it's modally presented.
Think about this - A user is in a hypothetical Mail app. They start typing out an email and set a font size and a color. They tap on the add attachment button, which brings up a modal view controller that allows them to select a picture. They select the picture and the modal view is dismissed, and in your implementation, the mail composing interface would have reset and the email content would be gone or at the very least the selected font size and color would be back to the default. That's not a good experience.

Remove View Controller from memory?

I seem to be having some trouble finding the answer to this one.
My Application loads view controllers using this code:
World_Pick *world_pick = [[World_Pick alloc] initWithNibName:#"World Pick"
bundle:nil];
world_pick.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:world_pick animated:YES];
[world_pick release];
The problem is the previous view isnt being released from memory, and just adding on to it. I have tried stuff like
[self.view removeFromSubview];
[viewController release];
ViewController = nil;
None of which seem to work. Could someone help me?
Thanks
If I understand correctly what you mean, I would say that it is normal, when you present a view controller modally that the underlying view controller is not removed and the view remains there. This is how modal view controllers are presented asa far as I know.
I don´t know what UI you are trying to build into your app, but maybe you should look into using a UINavigationController or, possibly, just adding/removing your views to a base view as need arise. This is of course just a guess, I don´t know what you are trying to do but if you provide more detail, I can help further.
The view controller that's presenting world_pick, the one that's self in the code above, should probably be left alone -- it's presenting a modal view controller, after all, and you'll go back to that view controller when the modal controller is dismissed. The view that it manages should also be left alone. It may be unloaded if there's a memory warning, but if there's memory available it should remain so that it's in place when the modal view controller is dismissed.
Is there some reason you're concerned about this?