我在工作的應用程序中有一個功能,與其他操作相比,它有時需要相當長的時間。我希望在執行該功能時顯示圖像,以向用戶顯示應用程序仍能正常工作。何時刷新UIView?是否有可能強制中功能刷新?
的方式我儘管可以做的是:
_checkImpossibleImage.hidden = NO;
bool ratioIsPossible = [PaintGame isPossible:_paintChipRatio:_paintCanRatios];
_checkImpossibleImage.hidden = YES;
從本質上講,這將圖像設置爲可見,執行的功能,然後將圖像設置爲不可見。但是,直到執行本節中的所有代碼之後,視圖纔會更新。下面是功能全面:
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0){
// Do nothing (cancel option selected)
} else {
if (_buttonKey == @"New") {
_checkImpossibleImage.hidden = NO;
bool ratioIsPossible = [PaintGame isPossible:_paintChipRatio:_paintCanRatios];
_checkImpossibleImage.hidden = YES;
...
}
...
}
}
有沒有辦法來迫使當前視圖更新或是否有更好的方法來創建一個「加載」彈出而函數執行?
你可能想看看進入[UIView文檔](http://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/setNeedsDisplay),特別是'needsDisplay'這將強制重繪。但是,我不知道發生在功能中間的重繪。 – 2012-07-18 00:06:18
基本上同樣的問題:[UIActivityIndicator工作不正常?](http://stackoverflow.com/questions/2919879/uiactivityindicator-not-working-properly) – 2012-07-18 00:33:24
此解決方案工作!謝謝你指出我朝着正確的方向。 – Valentine 2012-07-18 17:34:42