簡體   English   中英

MapKit:未調用 setSelected(_:animated:)

[英]MapKit : the setSelected(_:animated:) not called

在顯示 map 頁面中, annotationview視圖是自定義的,我在實現中覆蓋了setSelected(:)方法。 但是,當我單擊annotationView時,不會調用該方法。

- (void)setSelected:(BOOL)select {
    [super setSelected:select];  
  
    NSLog(@"select:+++++ %d", select);
}

NSLog不打印,為什么?

直接解決方案

如果您只想要一個直接的解決方案,這可能會有所幫助。

- (void)setSelected:(BOOL)select { 
    [super setSelected:select animated:YES]
  
    NSLog(@"select:+++++ %d", select);
}

執行

我在實現中覆蓋了setSelected(_:animated:)方法

如果是這樣,我認為您應該覆蓋以下方法而不是- (void)setSelected:(BOOL)select ,這是屬性selectedSetter方法。

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    .... // do your custom work
}

為什么以及如何

經過大量測試,我發現Super Class必須實現這個

- (void)setSelected:(BOOL)selected {
    
}

所以調用[super setSelected:select]時你什么也得不到

這很奇怪,但可能是合理的如果 Apple 不建議我們將selectedSetter方法覆蓋為- (void)setSelected:(BOOL)select已經完成了這項工作。

如您所見,這種方法存在於大部分 System Class 中。

暫無
暫無

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

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