views:

31

answers:

1

Hello

In appdidfinishlaunch I'm loading a tabbarcontroller as subview and after that im loading an other view

MySubView * mySubView = [[MySubView alloc] init];
[window addSubview:mySubView];
[mySubView release];

I want to close that toplayer with a buttonclick in the subview, so I set up an IBAction and tried diffrent things to force the actual view to close:

// 1.
[self.view removeFromSuperview];

// 2.
id  *delegate = [[UIApplication sharedApplication] delegate];
[[[delegate view] objectAtIndex:0] removeFromSuperview];


//3.
[[[delegate window] view] removeFromSuperview];

So how can i pop this subview from window ?

cheers Simon

+2  A: 

You could do a couple of things. One way would be to assign a unique tag to the view and get it using that tag later, so:

MySubView* mySubView = [[MySubView alloc] init];
[mySubView setTag:100];
[window addSubview:mySubView];
[mySubView release];

// later

[[[delegate window] viewWithTag:100] removeFromSuperview];

Another is to iterate through the window's subviews until you find one that is an instance of your unique class, then remove that. So:

MySubView* mySubView = nil;
for( UIView* view in [[delegate window] subviews] ) {
  if( [view isKindOfClass:[MySubView class]] ) {
    mySubView = (MySubView*)view;
    break;
  }
}
[mySubView removeFromSuperview];
Jason Coco
i got the concept and tried both variations but I only get errors. mostly: unrecognized selector sent to instance. also i changed [window addSubview:infostartView.view];
Simon
@Simon: You have to post more code or describe the problem more. If you have set up the way you described above, you won't get any error. I have no idea what an infostartView instance is, since you haven't provided any such context.
Jason Coco