I am trying to add a UIView to a view controller, but through an object of another class whose objects are currently present on the view controller in question.
myViewController is on screen -> It has objects of myNodeView added to it. I click on myNodeView and call a method in myViewController class to add a view to it.
I instantiate using myVc = [[myViewController alloc]init];
and then call the method. Is this the problem, that this is a new instance and that's why it does not add to the view currently visible. Please help me out.
Code -
// in nodeView
-(void)loadMap{
if(myVc==nil){
myVc=[[MyViewController alloc]init];
}
[myVc loadMapView];
}
// in MyViewController
-(void)loadMapView
{
if(mapView==nil)
{
self.mapView = [[MapView alloc]initWithFrame:CGRectMake(0, 0, 400, 400)];
self.mapView.backgroundColor=[UIColor whiteColor];
}
[self.view addSubview:self.mapView];
}