Question

I am practicing multiview but having a small problem.

When my new view gets loaded, I can still see previous view.

How to make previos view invisible??

Here is my code :-

- (IBAction)changeView:(id)sender 
{
    RedClass *red = [[RedClass alloc] initWithNibName:@"RedClass" bundle:nil];
    self.redClass = red;
    [red release];
    //[self.view removeFromSuperview];
    [self.view addSubview:redClass.view];        
}

and here is a screenshot :-

enter image description here

And when I uncomment [self.view removeFromSuperview] then my red view is not even getting loaded.

Any help would be appreciated.

Thanks

Was it helpful?

Solution

I think color of your red view may be transparant .

so please check it in your nib file of redclass. also check alpha for your red view it must be 1.

You can not remove your first view here. because it may be loaded at window or other controller. so if you are adding view2 in view 1 and removing view1 then view2 automatically get removed ,because it is already in view1 . so you can not write [self.view removeFromSuperview];

OTHER TIPS

You can declare view variable in .h file. and alloc it in viewDidLoad and don't release it there. Whenever you want to add view use, [self.view addSubview:red]; and when you want to remove you can use [red removeFromSuperview];

[self.view removeFromSuperview] removes the uiview which you is displayed. So you need to call removefromsuperview for previously loaded view and call addsubview for new one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top