1

我有以下代码:

- (IBAction)mapPressed:(id)sender
{
    MapViewController *mapVC = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:[NSBundle mainBundle]];
    mapVC.delegate = self;
    [self.navigationController pushViewController:mapVC animated:YES];
}

对于 MapViewController:

//MapViewController.h
@protocol MapViewDelegate
@required
- (void)selectedPlacemark:(MKPlacemark*)placemark;
@end
//...
@property (nonatomic, weak) id<MapViewDelegate> delegate;
//...

如果启用了 ARC,我还需要将 mapVC.delegate 设置为 nil 吗?如果是这样,这是否意味着我不应该在本地创建 MapViewController 而是为对象设置一个实例变量?

4

1 回答 1

0

刚刚通过this question确认您不需要将引用设置为nil。上面的代码一切都应该没问题。

于 2012-04-20T10:10:04.660 回答