我遇到了一个奇怪的问题。我想在我当前的视图中添加一个 UIViewcontroller(称为 iView)。我通过调用来做到这一点
iView = [[KFKaraokeInfosView alloc] initWithKaraoke:karaoke NibName:@"InfosView" commingFromPlayer:NO];
iView.songTitle.text = karaoke.title;
[self.view addSubview:iView.view];
在 iView 的 viewDidLoad 中,我将它作为观察者添加到 NotificationCenter 以获得某个通知,像这样
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"About";
if ([karaoke.styles count] == 0)
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"GetInfosOfSong" object:self.karaoke];
}
else
{
shouldSetup = YES;
}
[self.navigationController setNavigationBarHidden:NO animated:YES];
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setup) name:GetSongInfos object:nil];
[optionsTableView setBackgroundView:nil];
}
问题是当我在初始化时在 iView 上调用 autorelease 方法时,通知永远不会被捕获(因此永远不会调用 setup 方法),但如果我不为 iView 调用 autorelease,它就可以工作。
我不明白这种情况下的内存管理,有人可以帮我理解吗?