I have an Application where you can go to one view from two controllers and I was wondering whether it was possible to check which it came from so that I can do different things depending on the controller it came from.
Thanks in advance
I have an Application where you can go to one view from two controllers and I was wondering whether it was possible to check which it came from so that I can do different things depending on the controller it came from.
Thanks in advance
I might have to write a custom initialization method and pass something along it during init.
There will be different ways to do. This is one of the way
in yourView.h
-(id)initWithType:(int)viewControllerType;
Also create a int variable suppose int viewType; in yourView.h
in yourView.m file
-(id)initWithType:(int)viewControllerType{
self = [super initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];
if (self) {
//custom init here
viewType = viewControllerType;
}
you can define first viewController to be 1 and second to be 2.
so when initialization that yourView in first viewController. Code should be something like
yourView *newView = [yourView alloc] initWithType:1];
so when initialization that yourView in second viewController. Code should be something like
yourView *newView = [yourView alloc] initWithType:2];
Now, things will be easier
if(viewType==1){
//do something particular for first view controller
}
if(viewType==2){
//do something particular for second view controller
}
If it did not work. Please share you code... Thanks
You can access the UINavigation stack to see which view is before the previous one assuming you push the new view.
Or create a custom init method for the single view you push to that allows you to pass in a variable as to which view it came from (sorry, really wordy).