简体   繁体   English

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

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

In the display map page, the annotationview is customized and I am overriding the setSelected(:) method in the implementation.在显示 map 页面中, annotationview视图是自定义的,我在实现中覆盖了setSelected(:)方法。 However, when I click annotationView , the method is not called.但是,当我单击annotationView时,不会调用该方法。

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

the NSLog not print, Why? NSLog不打印,为什么?

Direct Solution直接解决方案

If you only want a direct solution, this may help.如果您只想要一个直接的解决方案,这可能会有所帮助。

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

Implementation执行

I am overriding the setSelected(_:animated:) method in the implementation我在实现中覆盖了setSelected(_:animated:)方法

If so, I think you should override below method rather than - (void)setSelected:(BOOL)select , which is the Setter method of property selected .如果是这样,我认为您应该覆盖以下方法而不是- (void)setSelected:(BOOL)select ,这是属性selectedSetter方法。

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

Why and How为什么以及如何

After testing a lot, I find that Super Class must implentation this经过大量测试,我发现Super Class必须实现这个

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

So you will get nothing when calling [super setSelected:select]所以调用[super setSelected:select]时你什么也得不到

It's weird but may be reasonable If Apple does not recommend us to override selected 's Setter method as - (void)setSelected:(BOOL)select already do the job.这很奇怪,但可能是合理的如果 Apple 不建议我们将selectedSetter方法覆盖为- (void)setSelected:(BOOL)select已经完成了这项工作。

As you can see, this method exist in the most of System Class.如您所见,这种方法存在于大部分 System Class 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UITableViewCell setSelected:在iPad上调用两次动画 - UITableViewCell setSelected:animated called twice on iPad UITableViewCell选择器setSelected:animated:被多次调用? - UITableViewCell selector setSelected:animated: gets called many times? 为什么在初始化/加载时调用tableview的setSelected(_:animated :)和setHighlighted(_:animated :)方法? - Why is tableview's setSelected(_:animated:) and setHighlighted(_:animated:) method called on init/load? 自定义UITableViewCell和setSelected上的动画:动画: - Custom UITableViewCell and animation on setSelected:animated: UITableViewCell setSelected:动画时动画没有效果 - UITableViewCell setSelected:animated having no effect when animated iOS UITableViewCell setSelected:animated:总是动画= NO - iOS UITableViewCell setSelected:animated: always has animated = NO 用户选择时的多选行为不同于setSelected:animated: - Multi-selection behavior at user selection differs from setSelected:animated: 未调用 iOS MapKit completerDidUpdateResults - iOS MapKit completerDidUpdateResults not called swift4:在iPad上点击两次调用TableView setSelected函数 - swift4: TableView setSelected function called twice on iPad click 在tableview单元格上调用setSelected时,为什么我的选择状态无法保留? - Why is my selected state not preserved when called setSelected on tableview cell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM