How to display a UIViewController from an NSObject class?

There is a current view as a UIViewController that calls "LoginView", but I'm not there, I'm in the NSObject class, and I want to call, display another UIViewController , which is a call to "MapView". How can i do this? enter image description here

The problem is similar to the screenshot above.

+7
source share
6 answers

In your IBAction or specific method, write this:

 UIWindow *window=[UIApplication sharedApplication].keyWindow; UIViewController *root = [window rootViewController]; UIStoryboard *storyboard = root.storyboard; CustomViewController *vcc =(CustomViewController *) [storyboard instantiateViewControllerWithIdentifier:@"storyBoardID"]; [root presentModalViewController:vcc animated:YES]; 
+9
source

I assume that you are trying to access a member of the UIViewController from the UIViewController class from the NSObject class. Just pass the UIViewController member to the NSObject class. In this case, I am. What you can do is that you can modify, edit, delete, whatever you do in your UIView from another class. The following is an example of this.

Calling the NSObject Class from the UIViewController Class

 @implementation myViewControllerClass - (void) viewDidLoad { //Pass in the UIViewController object, in this case itself. [[myNSOBjectClass alloc] startViewController:self]; .... } 

Then from your NSObject

 @interface myNSOBjectClass{ //Global access to the view controller. UIViewController *viewController; } ... @implementation myNSOBjectClass ... //function that the caller calls to pass their UIViewController object - (void)startViewController:(UIViewController *)callerViewController{ viewController = [[UIViewController alloc]init]; //puts the caller view controller to the global member. viewController = callerViewController; ... } 

You now have a view controller at your fingertips!

Greetings!

+5
source

You cannot instantiate and display view controllers from a model. For models must be manageable .

In this case, you mentioned LoginView as a starting point. When a condition is met (perhaps a successful login?), You must update the base model accordingly and then display the MapView .

Inside LoginView :

 MapView *mapView = [[MapView alloc] init]; 

If your application uses a navigation controller:

 [self.navigationController pushViewController:mapView animated:YES]; 

Otherwise:

 [self presentViewController:mapView animated:YES completion:<nil or block>]; 
+2
source

Try this code. It will help you ......

In the button click action, you must submit your UINavigationController and the current ViewController. Because the NSObject class did not find this controller.

In your Button action, put this code:

 [demo login_method_called:self.navigationController withCurrentViewController:self]; 

In your NSObject.h class, put this code:

 #import <Foundation/Foundation.h> #import "Home_ViewController.h" @interface Method_Action_class : NSObject - (void)login_method_called:(UINavigationController*)navigation withCurrentViewController:(UIViewController*) controller; @end 

In your NSObject.m class, put this code:

 #import "Method_Action_class.h" @implementation Method_Action_class -(void)login_method_called:(UINavigationController*)navigation withCurrentViewController:(UIViewController*) controller { Home_ViewController *home = [[Home_ViewController alloc] initWithNibName:@"Home_ViewController" bundle:nil]; [navigation pushViewController:home animated:YES]; } @end 

And build your code.

+2
source

I created an obersver in view controller class and declare a push view controller method and send messages using the NSNotification center from the NSObject subclass, and it works well.

in the controller's field of view: [[NSNotificationCenter defaultCenter] addObserver: self selector: name @selector (ignipickView): kNotificationDismissPicker object: nil];

in the NSOject subclass: [[NSNotificationCenter defaultCenter] postNotificationName: object kMoveToAchievementView: nil];

0
source

I used this in my NSObject class:

 [[[UIApplication sharedApplication] delegate].window.rootViewController presentViewController:yourMapViewContorller animated:YES completion:nil]; 

Hope this is helpful.

0
source

All Articles