3

MKPinAnnotationViewのコールアウト内にUITableViewを表示しようとしています。ストーリーボードファイル内に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などでクラッシュします。

4

1 に答える 1

0

メモリに問題があるだけです。あなたがするとき

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

これは、自動解放されたPropertyDetailsViewControllerを返します。後で、そのビューをコールアウト アクセサリ ビューに割り当てるだけですが、誰もビュー コントローラを保持していません。メソッドが終了すると、ビューコントローラーの保持カウントはゼロになり、割り当てが解除されます。そのView Controllerの何かにアクセスすると、BAD_EXCEPTIONが発生します。

実際、BAD_EXCEPTION は通常、メモリの問題です (リリースが多すぎる、2 つの自動リリースなど)。「ゾンビ オブジェクトを有効にする」フラグを有効にすると、より適切に追跡できます。これにより、オブジェクトの割り当てが完全に解除されないため、失敗したオブジェクトを確認できます。

于 2012-11-01T20:26:59.413 に答える