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