Supermannoying Supermannoying - 2 months ago 12
iOS Question

Loading other different viewController with parameter

In my viewController2 I have different UIView's, and let's say that when I load my viewController2 from viewController3 I need to show only UIView2. Is it possible to do that?

viewController2, has many forms. For example, after clicking the button on form1 it would hide form1 and show form2 and so on. Now, the problem is if I load my viewController2 from viewController3 is it possible to just show form2 and not form1?

Here's how I load my viewController2:

[APP_DELEGATE setUIBlockingEnabled:[NSNumber numberWithBool:NO]];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.rootViewController = nil;
appDelegate.rootViewController = [[RootViewController alloc] init];
appDelegate.window.rootViewController = appDelegate.rootViewController;
appDelegate.window.backgroundColor = [UIColor clearColor];
RegistrationViewController *controller = [[RegistrationViewController alloc]init];
[appDelegate.rootViewController moveToViewController:controller];


@property (nonatomic, strong) UIView *rectHolder1;
@property (nonatomic, strong) UIView *rectHolder2;

rectHolder1 and rectHolder2 has different subviews, and upon page load I am showing rectHolder1 and rectHolder2 is not visible. When the user clicks on the rectHolder1's button it would hide rectHolder1 and show rectHolder2. Now how can I directly show rectHolder2 if I am loading viewController2 from another viewController


You should have to manage this kind of stuff in viewWillAppear of your viewController2. Set some flag when you come from VC3 to VC2 so that you can differentiate that you are coming from VC3 or not! If your flag is true(I mean you are coming from VC3) then show your desired view else show other content that you want to show! If you are going forward means you have pushing VC2 from VC3(which less possible as per naming of viewcontrollers) then you can use prepareforsegue to set flag! If you are popping to VC2 from VC3 then you can use delegate and protocol or NSUserDefaults for store or set the flag!