如果我们像调用自己的方法一样调用委托方法有什么问题吗

发布于 2024-12-11 06:23:06 字数 195 浏览 0 评论 0原文

当用户单击按钮时,我正在调用 mkmapview 委托方法(regionDidChangeAnimated)。 这是正确的方法还是错误的方法? 我们可以调用委托方法吗?

因为,我有一些代码必须执行用户平移地图,因此当用户平移地图时,会自动调用 MapView 委托 RegionDidChangeAnimated,并且当用户按下按钮时我必须执行相同的操作。

I am calling a mkmapview delegate method (regionDidChangeAnimated) when the user clicked on a button.
Is that the right way or not?
Can we call delegate methods?

because, i have some code that has to execute we user pan the map, so when user pan the map automatically mapview delegate regionDidChangeAnimated called and i have to perform same action when user pressed a button.

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

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

发布评论

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

评论(1

一个人的旅程 2024-12-18 06:23:06

如果您问是否可以手动调用委托方法,那么答案是肯定的。你可以。

但是,这样做可能不是最佳实践。 MapView 的委托方法实际上应该只包含您想要在 MapView 调用它时运行的代码。我的建议是从委托方法中获取该代码,并将其放入新方法中。然后从委托方法调用该新方法(以及您想要的任何其他时间)。

这将确保您将来可以选择添加仅在地图视图的委托方法中运行的其他代码。

If you're asking whether you can call the delegate method manually, then the answer is yes. You can.

However, it's probably not a best practice to do so. The mapView's delegate method should really only contain code that you want to run when the mapView calls it. What I would suggest is to take that code from the delegate method, and put it in a new method. Then call that new method from the delegate method (and whenever else you want).

This will ensure that in the future you can choose to add additional code that runs only in the map view's delegate method.

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