簡體   English   中英

返回運行循環之前如何刷新顯示

[英]How to refresh display before returning to run loop

我試圖通過調用drawRect:或通過添加出現在前景中的視圖在前景中顯示消息。 必須在按下按鈕后顯示該消息。 我注意到只有在按下按鈕時調用的功能已退出時,才會顯示該消息。

- (IBAction)testBtnPress:(id)sender {
    TestView *testView = [[TestView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:testView];
    // processing to be done while the message is displayed
}

TestView類中調用drawRect: TestView 完成處理后,顯示帶有消息的矩形,這對我的應用程序不方便。 在運行過程中,是否有一種方法可以顯示消息(消息為“正在處理...請稍候”)。 謝謝。

處理必須在后台線程中完成,或者在runloop的一次迭代中執行,以使UI更改有時間處理。

您可以在runloop的下一個迭代中進行處理,如下所示:

TestView *testView = ... ;

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    // processing to be done while the message is displayed
}];

這應該工作:

dispatch_async(dispatch_get_main_queue(), ^{
    TestView *testView = [[TestView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:testView];
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM