我想在单击按钮 loadImgButton 时隐藏它。该按钮将调用以下方法:
- (IBAction)produceImage:(id)sender
{
[loadImgButton setHidden:YES];
[image1 setImage:[UIImage imageNamed:@"Fanny2.JPG"]];
[image2 setImage:[UIImage imageNamed:@"Fanny3.JPG"]];
NSLog(@"i am here");
for (int i = 0; i < 100000; i++) {
for(int j = 0;j < 10000; j++) {
}
}
}
The problem is that the button is not hidden and the image is not set until the function is finish. What is the reason cause this situation and how to fix it? Thanks!
最佳答案
UI 的更新发生在运行循环中,setHidden
等方法只是设置标志,以便以后可以更新 UI。您可能需要查看“Is there a way to make drawRect work right NOW?”以了解强制立即更新 UI 的方法。但是,您可能最好考虑其他方法来实现您所需的结果。
关于iphone - 我无法在功能完成之前隐藏按钮并设置图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10408561/