我在工作的应用程序中有一个功能,与其他操作相比,它有时需要相当长的时间。我希望在执行该功能时显示图像,以向用户显示应用程序仍能正常工作。何时刷新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