我想推出一個ViewController以編程方式導入到導航控制器,而我正在使用我的故事板來創建它。instantiateViewControllerWithIdentifier似乎調用viewdidload
這裏是我的代碼:
+ (void) pushViewController:(NSString *) identifier ForItems:(NSMutableArray *) items sender:(UIViewController *) sender {
GenericViewController *viewController = (GenericViewController *)[sender.storyboard instantiateViewControllerWithIdentifier:identifier];
viewController.items = [[NSMutableArray alloc] init];
[viewController.items removeAllObjects];
[viewController.items addObject:[[NSMutableArray alloc] init]];
[viewController.items[0] addObjectsFromArray:items];
[sender.navigationController pushViewController:viewController animated:YES];
}
在GenericViewController viewDidLoad
我用我的items
。由於一些突破點,我看到GenericViewController viewDidLoad
在instantiateViewControllerWithIdentifier
之後是正確的,items
等於零。
我以爲在pushViewController
方法中調用MyViewController viewDidLoad
。
任何想法爲什麼viewDidLoad
在instantiateViewControllerWithIdentifier
期間被調用?
---更新:---
這裏我viewDidLoad
- (void)viewDidLoad
{
for (MyItem *currentItem in self.items[0]) {
[Do Something]
}
[super viewDidLoad];
[...]
}
self.items
爲零。所以沒有做任何事情。
把完整的代碼please..what是myItem和viewDidLoad中method..the問題不this..cause當你啓動一個對象,它是活的。 –
您需要提供更多信息。顯示你使用instantiateViewControllerWithIdentifier的全部方法:方法instantiateViewControllerWithIdentifier:不會導致viewDidLoad被調用,所以其他事情正在進行。 – rdelmar
謝謝@rdelmar我很確定'instantiateViewControllerWithIdentifier'不要調用'viewDidLoad'。我更新我的代碼,我正在使用一個靜態管理器instanciate,並推動我的新viewController –