iphone - 我无法在功能完成之前隐藏按钮并设置图像

标签 iphone objective-c ios

我想在单击按钮 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/

相关文章:

ios - 为什么通知会自动从 iOS 通知中心删除?

iphone - 使用 Storyboard以编程方式更改应用程序语言

ios - 为什么我的 ViewController 在重新打开后不显示另一个 SKScene?

iphone - 如何在iPhone上播放网站上的音频文件?

iphone - Xcode 成功构建,但未复制到 iOS 设备,并立即终止调试器

objective-c - getaddrinfo 期间用户数量极少时出现 BAD_ACCESS

ios - 禁用单个 UIImageView 的自动布局

objective-c - NSFetchRequest setPropertiesToGroupBy : return all entities that match? 是否

ios - iOS读取TXT记录

iphone - 用数组填充操作表