模态视图控制器中的 MkMapView
我有一个 MkMapView 实例,我在 viewDidLoad 中调用它作为模态视图控制器:
mapView = [[MKMapView alloc] init];
mapView.showsUserLocation = YES;
mapView.delegate = self;
我只是创建它,这样我就可以针对它调用 ReverseGeocoder 并获取位置(地标)。它由视图保留,并且在第一次呈现视图时工作正常。我重复使用该视图,由 UITableView 中的不同项目调用,全部以模态方式呈现。第一次调用后,后续调用都不起作用。我正在挠头,想知道发布池是否有问题。
当视图调用 viewDidUnload 时,我将委托设置为 nil:
self.mapView.delegate = nil;
self.reverseGeocoder.delegate = nil;
有什么想法或我缺少的东西吗?
I have an instance of MkMapView that I'm calling in viewDidLoad for a modal view controller:
mapView = [[MKMapView alloc] init];
mapView.showsUserLocation = YES;
mapView.delegate = self;
I'm just creating it so I can call ReverseGeocoder against it and get a location (placemark). It's retained by the view and it works fine the first time the view is presented. I re-use the view, called by different items in a UITableView, all presented modally. After the first time it's called, none of the subsequent calls work. I'm scratching my head and wondering if there's something up with the release pool.
When the view calls viewDidUnload, I'm setting the delegates to nil:
self.mapView.delegate = nil;
self.reverseGeocoder.delegate = nil;
Any thoughts or something I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我更愿意考虑在
init
方法中创建这个对象,并在dealloc
中释放它,而不是担心视图加载时它是否存在。无论您是否将其显示在屏幕上,您都可以在init
方法中分配它,然后只需将其添加到viewDidLoad
中的视图(如果您选择)即可。I would much rather consider creating this object in your
init
method, and releasing it indealloc
rather than worrying about if it exists when the view loads. You can allocate it in yourinit
method regardless of if you're displaying it on-screen, and then just add it to your view inviewDidLoad
if you choose.