我有以下代码:

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

最佳答案

通过this question确认您不需要将引用设置为nil。上面的代码都应该可以。

关于objective-c - 自定义UIViewController委托(delegate)(ARC)怎么办?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10243995/

10-11 04:34