-1

I need to get in AppDelegate one parameter of some ViewController.

It not root for AppDelegate.

What is faster way to do it? Delegation?

Irfan
  • 4,301
  • 6
  • 29
  • 46
  • Down vote because of insufficient details provided for this question. You should share your code and view controller hierarchy before you expect anyone to help you with it. – Kunal Balani Mar 23 '14 at 04:14

2 Answers2

0

Make it a property on your VC and then your AppDelegate can access it as needed.

Dave Wood
  • 13,143
  • 2
  • 59
  • 67
  • I can not, I create this VC not from rootVC child – user3443009 Mar 23 '14 at 01:35
  • You should be able to add a property to any VC subclass. Doesn't matter if it's the rootVC or not. Or are you saying you don't have a variable pointing to the VC in order to access its properties? If so, make a property on your AppDelegate and either set your VC to it (so you can then access the other property), or just assign the variable in question to a property on the AppDelegate. – Dave Wood Mar 23 '14 at 02:47
0

First something is terribly wrong with your design otherwise there shouldn't be any need for you to do something like this.

Second, you haven't provided any relevant information about your VC hierarchy and there is no general solution for this.

However , here are few workarounds / patches:

1) If you are using storyboard you can use :

UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"mystoryboard"
                                              bundle:nil];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:@"ExampleViewController"];

2) You can make make view controller singleton and access it directly from AppDelegate

3) Hacky Method: In AppDelegate have a @property (nonatomic, retain) UIVIewController *hackyViewController;

In hackyViewController.m do this

-(void)viewDidLoad{
    // call super

    YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
    YourAppDelegate.hackyViewController =self;
}

Ideally , you should navigate through viewcontroller hierarchy using parentViewController and childViewcontroller property of UIVIewcontroller to get the instance. You can also make a recursive function which navigates through all childViewcontroller and check instance using iSKindOf to identify the viewcontroller you are looking for but this method does not work with all iOS configurations.

Kunal Balani
  • 4,739
  • 4
  • 36
  • 73