objective-c - 如何处理自定义 UIViewController 委托(delegate) (ARC)?

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

最佳答案

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

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

相关文章:

ios - 元素在 CCNode 中的定位

ios - SpriteKit : Stuttering during movement with constant velocity

c# - 为什么不调用第二个单点触控 View Controller 工具栏按钮事件处理程序

xcode - 使用 Storyboard或以编程方式创建 View 时自定义初始化

IOS:编程 rootViewController 以不同方式呈现 View 到 Storyboard 'isInitialView'

常量数组和内存管理

objective-c - 将 Sybase UltraLite Db 集成到我的代码中

ios - nw_host_stats_add_src recv 太小,收到 24,预计 28

ios - 在stringWithContentsOfFile期间记录错误消息

objective-c - 如何获取 SecKeychainRef 的属性?