【发布时间】:2011-10-17 13:42:07
【问题描述】:
在 ARC 用于 ios 开发之前,我一直在 viewDidLoad 中使用类似的东西来设置我的导航项:
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneClicked:)] autorelease];
如何在为我的视图控制器启用 ARC 的同时正确实现这一点,同时保持 1 行交易?
我知道在前面加上 __autoreleasing、__strong 等,但我不知道如何在不将其分成 2 行的情况下创建此 rightBarButtonItem:
__autoreleasing UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneClicked:)];
self.navigationItem.rightBarButtonItem = rightBarItem;
【问题讨论】:
-
__autoreleasing不应以这种方式使用。使用__autoreleasing的地方是在NSError **中经常看到的输出参数,即- (NSString *)doSomethingWithError:(NSError **)error变为- (NSString *)doSomethingWithError:(NSError *__autoreleasing *)error
标签: ios cocoa-touch automatic-ref-counting