ViewDeck issue with instances of viewcontrollers - ios

So on my center viewcontroller of my app I have a mapview. I click a button and it toggled my left viewcontroller and displays my left view controller. While I have my left viewcontroller open, I click a button and it closes the left viewcontroller and calls a method inside of the center view controller. It does actually call the method, but I think it is on another instance of the center view controller, because it does show NSLog, but it actually doesn't update information on the center view controller.
So basically, my issue is that I 'think' its creating multiple instances of the center controller. How an I access the FIRST instance to update data on it?
EDIT: Okay so heres some code.
FirstViewController *controller = (FirstViewController*)[self presentedViewController];
[controller doSnap];
I've tried several variations of this. Inside the method 'doSnap' I have an NSLog, and I have it do some things on the mapView. The stuff ends up getting logged, but it does not actually display on the map, and I think the reason of this is because it is a different instance of the view controller.

When using modal segues, you can just use the presentingViewController property to access the viewController that you came from.
YourOriginalViewController *controller = (YourOriginalViewController*)[self presentingViewController];
controller.yourPropertyToSet = whateverValue;

Related

how can I second time show my view controller without calling viewdidload?

here is my scenario case.
Initially for going to this VC without loading is hidden.when I click to first view controllers button it goes to second view controller.When I click button from secondVC it come back to first one and for going to this VC without loading button is now visible.Now when I click for going to this VC without loading I want to show my second view controller without reload because my previous loaded data for second view controller is needed.So how can I do that?
the actual scenario of my app look like this.My first VC
and the second one.
It's a picture of sound cloud but the case is same.
First possible solution,
Add SecondViewController as child view controller of FirstViewController using container view in Storyboard.
Every time you want to remove SecondViewController just hide/remove it with custom animation block.
Keep the reference of SecondViewController in FirstViewController
Second possible solution,
Create shared data object.
Then you can use that shared data object in any view controller, regardless of saving the state of any view controller.
I would create an object where i put the data und pass this from ViewController to ViewController by properties. Maybe this is to simple but it should work.

Move to start of storyboard from button on last screen

I'm trying to get a storyboard to bring the user back to the first screen of a storyboard when a button is pressed.
I have the button click hooked up and the method is hit when it's tapped but it's either doing nothing or crashing the app depending on what I've got in that method (I've tried so many things at this stage that I can't remember the original setup)
The best I can achieve is that once tapped the user gets brought to the third screen in the storyboard, rather than the first.
Here's the storyboard, I want to get the user to move from the button circled in red back to the very first view controller (top left of screenshot).
Maybe the storyboard layout will help people, I'll post some of the various methods I've tried as well.
Here's the method
- (IBAction)done:(id)sender
{
//Multitude of attempts have been in here, either they don't do
//anything or they just send the user back to the NEW REPORT screen.
//Button does nothing in these following events
[self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
}
If you want to start fresh, have the button instantiate a new instance of the first controller, and set it as the window's root view controller:
FirstViewController *first = [self.storyboard instantiateViewControllerWithIdentifier:#"First"];
self.view.window.rootViewController = first;
It's not clear to me exactly how you're getting to that controller with the button in question, but you might want to put dealloc methods in all your controllers with a log to see if all are getting deallocated at some point in your navigation, and when you go back to the new first controller as I've outlined above.

Firing a segue from a different view

I have a segue that navigates from FirstViewController to SecondViewController. This happens by the press of a button. The code for the button is
- (IBAction)segue:(id)sender {
[self performSegueWithIdentifier:#"myIdentifier" sender:self];
}
This happens correctly when i press the button.
What i am trying to do is fire this method from another view. I tried doing
FirstViewController fvc = [[FirstViewController alloc] init];
[fvc segue:nil];
When i try this, I get the error message, Reciever has no segue with identifier 'myIdentifier'
How do i fire this segue programatically from another view?
There are a few issues here, but they boil down to a couple of key points:
Segues are a storyboard thing, so view controllers only "know" about segues if they're instantiated from a storyboard.
A view controller must be onscreen to perform a segue.
Segues are transitions from one specific view controller to another specific view controller.
So, in your snippet:
FirstViewController fvc = [[FirstViewController alloc] init];
[fvc segue:nil];
The first problem is that alloc-init-ing gives you an instance of FirstViewController that doesn't know anything about the storyboard it came from, so it doesn't know anything about segues. (This alone could be fixed using [instantiateViewControllerWithIdentifier:][1], but that doesn't solve your whole problem.) A second problem is that this instance doesn't fit anywhere into the UI hierarchy -- it hasn't been presented as a modal view controller, it's not the top view controller in the current navigation controller, it's not the visible window's root view controller, etc. In order to transition the screen from one view to another, the first view needs to be onscreen.
What it sounds like you want to do is transition from what's currently onscreen to the target of this segue. But the notion of a storyboard segue isn't just a transition with a destination -- it's a source, a destination, and a transition or relationship between them. If you have a different source view, you need a different segue. So, if you already have a segue from FirstViewController to SecondViewController, and you want to make a similar transition from OtherViewController (assuming that's the one onscreen now) to SecondViewController, you need to make a second segue connecting OtherViewController to SecondViewController.

Show custom view after person is selected in peoplePickerNavigationController

I'm running into trouble with what I think is a pretty basic task. Within peoplePickerNavigationController:peoplePicker:shouldContinueAfterSelectingPerson: i want to show my own view rather than the standard person view. I'm using a Storyboard, but don't think I can simply manually segue to a window here so I'm thinking I need to create a new XIB with a View Controller in it. I'm setting the Class of the View Controller to my custom View Controller in IB. Then in peoplePickerNavigationController:peoplePicker:shouldContinueAfterSelectingPerson: I'm doing:
MyVC *myVC = [[MyVc alloc] initWithNibName:#"XIBFileName" bundle:nil];
[self presentModalViewController:myVC animated:YES];
In my View Controller initWithNibName gets called, but not viewDidLoad. What am I doing wrong here?
Just try [peoplePickerVC presentModalViewController:myVC] instead of presenting from self.
The issue is that the peoplepickerviewcontroller will be in the top of the navigation stack. Becuase you wud've presented the peoplepicker from self. As this is the case, you wont be able to present/push from self as its not at the top of the navigation stack.
Otherwise once the peoplepicker has been poped, then you can further present from self.

I dont want to add UInavigationController and tabbarcontroller on root view controller

I have a single view based app, when it runs it shows 2 button. On tap of 1 button i want to switch to another view which must be uinavigationcontroller and on 2 button i want to switch to tabbarcontroller view. I know what uinav and tabbar controllers can do. I created uinav and tab based project and study all the code, searched on internet for tutorials but what i get is everyone telling to add like this
self.window.rootViewController = self.navigationController;
on rootviewcontroller.
I dont want to add UInavigationController and tabbarcontroller on root view controller. Please help me solving this issue.
Thanks.
Then create a UIViewController called RootViewController for example, add two buttons inside its view and handle the touch events for those buttons. The first button, when touched should present your UINavigationController and the second button should present your UITabBarViewController. Then in your AppDelegate's didFinishLaunchingWithOptions: method initialize your RootViewController and set the self.window.rootViewController = rootViewController;
(UPDATE)
Allright, create a SingleView application. Put the buttons and set up the outlets and actions for those buttons. You also need to create 2 more view controllers: one UINavigationController and one UITabBarController. When the first button is touched, in the method which handles the touch add:
-(void)button1Touched:(id)sender
{
MyNavivationController *navc = [[MyNavigationController alloc] init];
[self presentViewController:navc animated:YES completion:nil];
}
You can do the same with the other button, but there initialize your tab bar controller and do the same. If you are unfamiliar with those operations you may refer to the documentation on how to create view controllers, handle events and etc...
#pamy I can provide you complete source code please let me know your skype id or other way to send you the file, i don't know how to post the code on stackoverflow.
I did write many times but it's not accepting my code.

Resources