开发者

iOS - How to remove previous view after loading a new view?

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开发者_Go百科??

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 :-

iOS - How to remove previous view after loading a new view?

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

Any help would be appreciated.

Thanks


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];


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜