实例变量在UINavigationController中的ViewController中不起作用

我仍然对iOS开发不熟悉,但遇到了一个我无法解决的问题,而且我尝试在网上查找,但找不到任何东西。实例变量在UINavigationController中的ViewController中不起作用

我正在使用UIImagePickerController来选择和图像,我在App Delegate中使用它。当图像返回时,在imagePickerController:didFinishPickingMediaWithInfo方法中,我想用视图控制器制作一个新的导航控制器,并将其放在“应用程序”上。

这里是我如何做它:

CustomNavigationController *customNavigationController = [[CustomNavigationController alloc] init]; 

PhotoViewController *photoViewController = [[PhotoViewController alloc] initWithNibName:@"PhotoViewController" bundle:[NSBundle mainBundle]];

[customNavigationController pushViewController:photoViewController animated:NO];

[customNavigationController.view setFrame:[[UIScreen mainScreen] applicationFrame]];

[photoViewController release];

[self.window addSubview:customNavigationController.view];

//Call method of photoViewController.

[[customNavigationController.viewControllers objectAtIndex:0] addPhotoFromData:info];

[self.tabBarController dismissViewControllerAnimated:YES completion:nil]; //Get rid of UIImagePickerController

在photoViewController

不过,我并没有获得合成和viewDidLoad中加载的任何实例变量。他们都返回null。还有一个tableView和调用重载tableView实际上并不会导致tableView响应。

下面是一些代码从photoViewController

- (void)viewDidLoad 

{

[super viewDidLoad];

self.photoCount = 0;

self.timestamp = [[NSDate date] timeIntervalSince1970];

self.photos = [[NSMutableArray alloc] initWithCapacity:5];

self.photosData = [[NSMutableArray alloc] initWithCapacity:5];

self.uploadingCount = 0;

UINib *customCell = [UINib nibWithNibName:@"CustomTableCell" bundle:[NSBundle mainBundle]];

[self.tableView registerNib:customCell forCellReuseIdentifier:@"customCell"];

self.tableView.separatorColor = [UIColor clearColor];

NSLog(@"%@", self);

}

,也是addPhotoFromData方法:

- (void)addPhotoFromData:(NSDictionary *)info 

{

[self.photos addObject:info];

NSLog(@"%@", self.photos); //Doesn't add "info" and does not return anything when later called from other methods.

[self.tableView reloadData]; //Doesn't work

一切工作之前,我在UINavigationController的补充。我完全失去了。

编辑:经过一些更多的调试尝试后,我发现调用addPhotoFromData时未加载视图。 viewDidLoad被称为后缀。有没有办法延迟方法调用?

回答:

任何原因您不能在viewDidLoad方法内的PhotoViewController调用addPhotoFromData:?您始终可以从视图控制器访问应用程序代理的属性:

YourAppDelegateType * delegate = [UIApplication sharedApplication].delegate; 

[self addPhotoFromData:delegate.info];

以上是 实例变量在UINavigationController中的ViewController中不起作用 的全部内容, 来源链接: utcz.com/qa/260430.html

回到顶部