mapkit:setSelected(_:动画:)未调用

发布于 2025-01-25 20:34:13 字数 312 浏览 4 评论 0原文

在“显示映射”页面中,自定义了AnnotationView,我正在实现中覆盖setSelected(:)方法。但是,当我点击 AnnotationView,该方法未调用。

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

nslog不打印,为什么?

In the display map page, the annotationview is customized and I am overriding thesetSelected(:)method in the implementation. However, when I click
annotationView, the method is not called.

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

the NSLog not print, Why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云淡月浅 2025-02-01 20:34:13

直接解决方案,

如果您只需要直接解决方案,这可能会有所帮助。

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

执行

我正在覆盖setSelected(_:animated:)实现中的方法

如果是的,我认为您应该覆盖下面的方法,而不是- (void)setSelected:(bool)选择,这是 setter 属性的方法选择

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

为什么以及如何

经常测试后,我发现super类必须将其固化,

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

以便在调用[super setSelected:select]时,您将一无所获,

这很奇怪,但是如果Apple不建议我们覆盖selected's setter 方法- (void)SetSelected :( bool)选择已经完成了工作。

如您所见,此方法存在于大多数系统类中。

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

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)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

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

So you will get nothing when calling [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.

As you can see, this method exist in the most of System Class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文