首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在UITableView中显示MKPinAnnotationView

在UITableView中显示MKPinAnnotationView
EN

Stack Overflow用户
提问于 2012-07-10 17:47:59
回答 1查看 937关注 0票数 3

我试图在UITableView的标注中显示一个MKPinAnnotationView。我在我的故事板文件中添加了UITableViewController。我使用以下代码将leftAccessoryView分配给UITableView。

代码语言:javascript
复制
- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id < MKAnnotation >)annotation
{
    if([annotation isKindOfClass:[MKUserLocation class]])
        return nil; 

    NSString *annotationIdentifier = @"ZillowPropertyDetailsIdentifier"; 

    MKPinAnnotationView *propertyDetailsView = (MKPinAnnotationView *) [mv 
                                                            dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];

    if (!propertyDetailsView) 
    {
        propertyDetailsView = [[MKPinAnnotationView alloc] 
                    initWithAnnotation:annotation 
                    reuseIdentifier:annotationIdentifier];

        // get view from storyboard 
        PropertyDetailsViewController *propertyDetailsViewController = (PropertyDetailsViewController *) [self.storyboard instantiateViewControllerWithIdentifier:@"PropertyDetailsIdentifier"];

        propertyDetailsView.leftCalloutAccessoryView = propertyDetailsViewController.view;

        [propertyDetailsView setPinColor:MKPinAnnotationColorGreen];
        propertyDetailsView.animatesDrop = YES; 
        propertyDetailsView.canShowCallout = YES; 

    }
    else 
    {
        propertyDetailsView.annotation = annotation;
    }

    return propertyDetailsView; 
}

PropertyDetailsViewController:

代码语言:javascript
复制
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    // Return the number of rows in the section.
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...

    return cell;
}

当我点击引脚时,它会与BAD_EXCEPTION或其他东西崩溃。

EN

回答 1

Stack Overflow用户

发布于 2012-11-01 20:26:59

你只会有记忆问题。当你做的时候

代码语言:javascript
复制
PropertyDetailsViewController *propertyDetailsViewController = (PropertyDetailsViewController *) [self.storyboard instantiateViewControllerWithIdentifier:@"PropertyDetailsIdentifier"];

返回一个自动发布的 PropertyDetailsViewController。稍后,您只需指示它对标注附件视图的视图,但是没有人保留视图控制器。子方法完成时,视图控制器保留计数为零,并将其解除分配。当访问该视图控制器上的任何内容时,将引发BAD_EXCEPTION。

实际上,BAD_EXCEPTION通常是一个内存问题(太多的版本,两个自动版本等等)可以更好地跟踪它们,激活“启用僵尸对象”标志。这使得对象不能完全释放,这样您就可以看到哪个对象失败了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11418974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档