如何处理自定义UIViewController委托(ARC)?

时间:2012-04-20 09:56:33

标签: objective-c ios uiviewcontroller delegates automatic-ref-counting

我有以下代码:

- (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,而是为对象设置一个实例变量?

1 个答案:

答案 0 :(得分:0)

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