2012-07-10 87 views
3

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

- (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:

- (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什么崩溃的引脚上。

+0

是你的propertyDetailsViewController有效(非零),有效视图? – Marco 2012-07-10 17:53:21

+0

properyDetailsViewController是有效的,它在Storyboard中。我用PropertyDetailsViewController更新了代码。很少有可能成为兴趣点的方法。 – azamsharp 2012-07-10 17:57:19

+0

让我尝试使用UIPopUPController并在其中显示tableview。 – azamsharp 2012-07-10 18:09:25

回答

0

您只有内存问题。当你做

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

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

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