لماذا لا تحتفظ initWithRootViewController فئة viewController الذي تم تمريره في ذلك؟

StackOverflow https://stackoverflow.com/questions/1054993

  •  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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top