【发布时间】:2012-10-17 07:21:57
【问题描述】:
我无法访问在AppDelegate 中定义的UIImagePickerController。我已经在AppDelegate.h 文件中定义了UIImagePickerController 对象也使用了它的委托。这是我的代码。
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.wantsFullScreenLayout = YES;
picker.allowsEditing=NO;
return YES;
}
我正在 viewcontroller 文件中使用操作表,并希望以 -
的方式执行此操作viewController.m
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (actionSheet.tag)
{
case 1:
switch (buttonIndex)
{
case 0:
{
AppDelegate *appDelegate = (AppDelegate*) [[UIApplication sharedApplication] delegate];
[appDelegate.window.rootViewController presentModalViewController:appDelegate.picker animated:YES];
}
}
}
}
但是图像选择器控制器视图没有显示。
【问题讨论】:
-
您正在测试哪个 iOS 版本?
presentModalViewController是一种已弃用的方法。你应该改用presentViewController:animated:completion:。 -
检查您是否在 .h 文件中正确分配了委托。那就是
... -
[appDelegate.window.rootViewController presentModalViewController:appDelegate.picker animated:YES completion:nil];也不行。
-
一切正常。我在 .h 文件中连接了 UIImagePickerControllerDelegate、UINavigationControllerDelegate。
-
在哪里初始化窗口并设置 window.rootViewController?
标签: iphone objective-c ios cocoa-touch uiimagepickercontroller