0
MyAppDelegate正在做一些背景的東西,在這段時間需要刷新幾個視圖,所以我保存了每個創建的控制器的引用。如何處理保存在AppDelegate中的控制器的保留計數?
@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
SomethingController *currentSomethingController;
}
@property (nonatomic, retain) SomethingController *currentSomethingController;
這樣做是爲了打開控制器:
- (void)openSomethingController {
MyAppDelegate * app = [[UIApplication sharedApplication] delegate];
app.currentSomethingController = [[SomethingController alloc] init];
[self presentModalViewController:app.currentSomethingController animated:NO];
}
這就是所謂的控制器內將其關閉:
- (void)dismissSelf
{
MyAppDelegate * app = [[UIApplication sharedApplication] delegate];
[app.currentSomethingController release];
app.currentSomethingController = nil;
[self dismissModalViewControllerAnimated:NO];
}
在MyAppDelegate控制器是將消息發送到控制器:
- (void)longRunningBackgroundTask {
[currentSomethingController performSelectorOnMainThread:@selector(updateData) withObject:nil waitUntilDone:YES];
}
如果我執行產品 - >分析,則會收到「潛在泄漏」和「不正確減量」警告。這樣做的正確方法或假設我的方法沒問題,我如何告訴分析工具忽略這些線?
我以爲財產只是保留,沒有釋放的對象,所以混亂不僅是外部讀者的。感謝您指出正確的方式來做到這一點! –