0

我还是 iOS 开发的新手,但我遇到了一个我无法解决的问题,我尝试在网上查找,但还没有找到任何东西。

我正在使用 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 被称为后记。有没有办法延迟方法调用?

4

1 回答 1

1

有什么理由不能addPhotoFromData:viewDidLoad方法中调用 PhotoViewController 吗?您始终可以从视图控制器访问应用程序委托的属性:

YourAppDelegateType * delegate = [UIApplication sharedApplication].delegate;
[self addPhotoFromData:delegate.info];
于 2012-11-20T03:34:18.393 回答