【问题标题】:Unable to show uiimagepickercontroller无法显示 uiimagepickercontroller
【发布时间】: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


【解决方案1】:

在你的

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 

不要写

 [appDelegate.window.rootViewController presentModalViewController:appDelegate.picker animated:YES];

试着写

 [appDelegate.window presentModalViewController:appDelegate.picker animated:YES];

让我知道它是否有效。!!! 快乐编码!!!!!!

【讨论】:

    【解决方案2】:

    我相信objective c 现在会自动合成你的属性并且期待ivar 的_picker。用于表示法来访问您的选择器,如 self.picker 或 self.delegate.picker

    【讨论】:

      猜你喜欢
      • 2019-09-14
      • 1970-01-01
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多