开发者

how to remove previous views in ViewWillApear?

I have TabBarController in app, so all tab bar items are loading at same time,,

when I am update data, and coming back, then previous views are still there and new views are added above them

what should I do

my C开发者_运维技巧oding is in ViewWillApear,

I haven't code in ViewDidLoad because I want to see data as I update them in database,

and ViewDidLoad is being called once, but ViewWillApear is being called everytime, so everytime new views are added and previous are there,,,,

hope you understand what I mean,,,


You want the values displayed by those views or you want to update the views in all.

If you want to update only values, then do that in viewWillAppear: no need to create and add the whole views again. Its not good practice.

Create the views once only in loadView or viewDidLoad: method. and assign them values in viewWillAppear:

or else in your

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];

    [self removeAllSubviews];

    //OR
    for(UIView * view in self.view.subviews)
    {
            [view removeFromSuperview];
            view = nil;
    }

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜