長いジョブを実行中に UIActivity
1 UIActivityIndicatorV iew* wAI = [ [ [ UIActivity IndicatorV iew alloc ] initWithAc tivityIndi catorStyle :UIActivity IndicatorV iewStyleWh iteLarge ] autoreleas e ]; 2 [ [ UIApplicat ion sharedAppl ication ].keyWindow addSubview :wAI ]; 3 wAI.center = CGPointMak e( 160, 240 ); 4 [ wAI startAnima ting ]; 5 [ self 長いジョブ ]; 6 [ wAI removeFrom Superview ]; 7
表示させるための一つ目のアイディアは以下のように currentRun
1 [ wAI startAnimating ]; 2 [ NSRunLoop.currentRun Loop runUntilDa te:[ NSDate dateWithTi meInterval SinceNow:0.0 ] ]; 3 [ self LongJob ];
2つ目のアイディアはジョブとインディケータを currentRun
1 wAI.startAnimating; 2 [ self performSel ector:@selector(LongJob) withObject :nil afterDelay :0 ]; 3 [ wAI performSel ector:@selector(removeFrom Superview) withObject :nil afterDelay :0 ]; 4
ネットで別スレッドでやってる例をよく見るが、その必要はない。
単に currentRun
posted by
Saturn
on Wed 12 Jan 2011
at 04:07