![](/img/trans.png)
[英]Should becomeFirstResponder() always be called on the main thread?
[英]Is observeValueForKeyPath always called from the main thread?
observeValueForKeyPath
總是從主線程調用嗎?
我正在記錄電話
-(void) observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
NSLog(@"KVO: isMainThread %d", [NSThread isMainThread]);
// ...
}
它似乎每次打印1
,但我無法在文檔中找到任何保證。 任何人都可以證實這是事實嗎?
一般來說,沒有。
您在更改值的線程上收到observeValueForKeyPath:ofObject:change:context:
更改值的setter方法在更新值之后和返回之前將消息發送給所有觀察者。
如果您只在主線程上調用setter,那么您將只觀察主線程上的更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.