MKMapView错误

发布于 2024-11-27 19:32:34 字数 681 浏览 3 评论 0原文

我猜错误太严重了,因为它的工作原理与我想要的完全一样,但我收到了一条令人不安的警告消息。我将 UIViewController 添加到 TabBarController,我想要它做的就是显示地图视图,然后在用户单击该选项卡时放大用户。我构建了 xib,我所做的唯一编辑是将 MKMapView 拖过来并连接插座和委托。除此之外,这是所有实现代码:

- (void)viewDidLoad
{

    [super viewDidLoad];

    [mapView setShowsUserLocation:YES];

}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {

    CLLocationCoordinate2D loc = [userLocation coordinate];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
    [mapView setRegion:region animated:YES];

}

问题是我在最后一行收到黄色警报错误,其中显示““mapView”的本地声明隐藏了实例变量”。

但是,当我运行该应用程序时,它似乎工作正常。这个错误可能指的是什么?

I guess error is too strong as it works exactly like I want it to, but I am getting a warning message that is troubling. I am adding a UIViewController to a TabBarController and all I want it to do is display the Map View and then zoom in on the user when the user clicks on that tab. I built the xib and the only editing I did was to drag an MKMapView over and hook up the outlet, as well as the delegate. Other than that, this is all the implementation code:

- (void)viewDidLoad
{

    [super viewDidLoad];

    [mapView setShowsUserLocation:YES];

}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {

    CLLocationCoordinate2D loc = [userLocation coordinate];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
    [mapView setRegion:region animated:YES];

}

The problem is that I am getting a yellow alarm error on the final line that says, "Local declaration of "mapView" hides the instance variable."

However, when I run the app, it seems to be working correctly. What could this error be referring to?

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

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

发布评论

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

评论(2

世界和平 2024-12-04 19:32:34

发生这种情况是因为您将 MKMapView 对象声明为 mapView。查看方法声明:

- (void)mapView:(MKMapView *)mapView

它使用与您自己的变量相同的名称。这就是编译器似乎遇到问题的地方。我自己已经遇到过几次这种情况,我的解决方案是更改我的变量名称(例如,您可以使用 worldView)。

我想你也可以自己解决。与其他语言一样,您可以使用 this.variableName,我认为您可以使用 self.variableName 来指示这是“您的”变量。如果这有道理吗?

当我声明自己的方法时,我通常这样做:

 - (void)feedDog:(Dog *)aDog;

然后我的变量将被称为 Dog 以避免混淆。

这就是我所做的。如果有人对此有任何补充,请随时补充。我对此还很陌生,但我现在确实遇到过这个错误几次。

This is happening because you declared your MKMapView object as mapView. Look at the method declaration:

- (void)mapView:(MKMapView *)mapView

it uses the same name as your own variable. This is where the compiler seems to run into a problem. I've had this a couple of times myself now, and my solution was to change my variable name (you could use worldView, for example).

I think you could also solve it with self. Like in other languages, you would use this.variableName, I think you can do self.variableName to indicate that this one is 'your' variable. If that makes sense?

When I declare my own methods, I usually do like this:

 - (void)feedDog:(Dog *)aDog;

and then my variable would be called Dog to avoid confusion.

Just what I do. If anyone has anything to add to this, feel free to. I'm still fairly new to this, but I did run into this error a couple of times now.

洛阳烟雨空心柳 2024-12-04 19:32:34
[self.mapView setRegion:region animated:YES];
[self.mapView setRegion:region animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文