gpt4 book ai didi

ios - 在 MKPinAnnotationView 中显示一个 UITableView

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:44:57 26 4
gpt4 key购买 nike

我正在尝试在 MKPinAnnotationView 的标注内显示一个 UITableView。我在 Storyboard 文件中添加了 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;
}

属性详细信息 View Controller :

- (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 或其他原因而崩溃。

最佳答案

你只是内存有问题。当你做的时候

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

返回一个autoreleased PropertyDetailsViewController。稍后您只需将其 View 分配给标注附件 View ,但没有人保留 View Controller 。儿子,当方法完成时,viewcontrollers 保留计数为零并且它被释放。当访问该 View Controller 上的任何内容时,将引发 BAD_EXCEPTION。

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

关于ios - 在 MKPinAnnotationView 中显示一个 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11418974/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com