لماذا لا تحتفظ initWithRootViewController فئة viewController الذي تم تمريره في ذلك؟
-
20-08-2019 - |
سؤال
ولدي مخصص يسمى viewController SourceListViewController، وأنا إضافته إلى UINavigationController، وجهة النظر التي ثم يضاف إلى نافذة التطبيق فون. بعد اجتياز SourceListViewController إلى UINavigationController، وإطلاق سراح sourceListViewController.
SourceListViewController *sourceListVC = [[SourceListViewController alloc] initWithNibName:@"SourceListViewController" bundle:nil];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:sourceListVC] autorelease];
[sourceListVC release];
وعندما أفعل هذا، فإن التطبيق تحطم بعد تحميل عرض على الهاتف. عندما علق بها السطر الأخير، وتعمل بشكل جيد التطبيق. ليس من المفترض initWithRootViewController الإبقاء على نسخة من sourceListVC؟
المحلول
وأنت autoreleasing navigationController. حتى إذا كان يحصل على autoreleased navigationController (والتي من المحتمل أن يحدث في runloop المقبل) حتى ذلك الحين سوف sourceListVC.
لا تنتمي إلى StackOverflow