我试图在UITableView的标注中显示一个MKPinAnnotationView。我在我的故事板文件中添加了UITableViewController。我使用以下代码将leftAccessoryView分配给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或其他东西崩溃。
发布于 2012-11-01 20:26:59
你只会有记忆问题。当你做的时候
PropertyDetailsViewController *propertyDetailsViewController = (PropertyDetailsViewController *) [self.storyboard instantiateViewControllerWithIdentifier:@"PropertyDetailsIdentifier"];返回一个自动发布的 PropertyDetailsViewController。稍后,您只需指示它对标注附件视图的视图,但是没有人保留视图控制器。子方法完成时,视图控制器保留计数为零,并将其解除分配。当访问该视图控制器上的任何内容时,将引发BAD_EXCEPTION。
实际上,BAD_EXCEPTION通常是一个内存问题(太多的版本,两个自动版本等等)可以更好地跟踪它们,激活“启用僵尸对象”标志。这使得对象不能完全释放,这样您就可以看到哪个对象失败了。
https://stackoverflow.com/questions/11418974
复制相似问题