不要在viewDidLoad中初始复杂的界面

      开发中一个详情界面的内容非常多,在从列表页进入详情界面时,在列表界面停顿很长时间后才进入详情界面。原因就是详情界面的初始化放在了viewDidLoad中,而在此时间内,会一直停在列表界面,用户的使用感受很不好。
解决方案:
1、在viewDidLoad中显法一个加载界面,

2、将界面初始化放在viewDidAppear中。

这样,用户就不会在从列表界面进入详情界面时界面时,等很长时间了。

 

@interface DetailVC :UIViewController

{

   BOOL _isAppear;

 

    UIView* _loadingView;

}

 

- (void)viewDidLoad

{

    [superviewDidLoad];

    

     _loadingView = [[UIViewalloc]initWithFrame:CGRectMake(0,200,320,30)];

     _loadingView.backgroundColor = [UIColorclearColor];

     [self.viewaddSubview:_loadingView];

        

     UIActivityIndicatorView *aiv = [[UIActivityIndicatorViewalloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

     aiv.frame =CGRectMake(99,3,25,25);

     aiv.backgroundColor = [UIColorclearColor];

     [_loadingViewaddSubview:aiv];

     [aivstartAnimating];

 

     UILabel* lblPrompt = [[UILabelalloc]initWithFrame:CGRectMake(129,0,98,30)];

     lblPrompt.backgroundColor = [UIColorclearColor];

     lblPrompt.font = [UIFontsystemFontOfSize:15.0];

     lblPrompt.textColor =DEEP_FOUNT_COLOR;

     lblPrompt.text =@"正在加载中······";

     [_loadingViewaddSubview:lblPrompt];

}

 
 

-(void)viewDidAppear:(BOOL)animated

{

    [superviewDidAppear:animated];

    

   if(_isAppear){return ;}

    _isAppear = YES;

 

    //注意!!!在此处执行复杂的界面初始化工作。   

 

    if(_loadingView){[_loadingViewremoveFromSuperview];}

}

 

猜你喜欢

转载自gypgyp.iteye.com/blog/1929103
今日推荐