不要在viewDidLoad中構建複雜的介面

來源:互聯網
上載者:User

         開發中一個詳情介面的內容非常多,在從列表頁進入詳情介面時,在列表介面停頓很長時間後才進入詳情介面。原因就是詳情介面的初始化放在了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];}

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.