Ios UIStatusBarStyleBlackTranslucent在此设备上不可用

Ios UIStatusBarStyleBlackTranslucent在此设备上不可用,ios,cocoa-touch,ipad,ios5,uistatusbar,Ios,Cocoa Touch,Ipad,Ios5,Uistatusbar,我有一个适用于iPad的UIActionSheet,它有三个选项: 取消 摄像机 照片库 当我触摸“照片库”选项时,我会收到一个崩溃和一条消息 UIStatusBarStyleBlackTranslucent在此设备上不可用 我读了,但没弄明白 有人能帮我吗 更新: -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex =

我有一个适用于iPad的
UIActionSheet
,它有三个选项:

  • 取消
  • 摄像机
  • 照片库
  • 当我触摸“照片库”选项时,我会收到一个崩溃和一条消息

    UIStatusBarStyleBlackTranslucent在此设备上不可用

    我读了,但没弄明白

    有人能帮我吗

    更新

    -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    
        if (buttonIndex == 0) 
        {
    
            imgController = [[UIImagePickerController alloc] init];
            imgController.allowsEditing = YES;
            imgController.sourceType =  UIImagePickerControllerSourceTypeCamera;   
            imgController.delegate=self;
            [self presentModalViewController:imgController animated:YES];
    
        } 
        else if (buttonIndex == 1) 
        {
            imgController = [[UIImagePickerController alloc] init];
            imgController.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
            imgController.delegate=self;
            [self presentModalViewController:imgController animated:YES];  
    }
    }  
    

    我在最后一行遇到崩溃,即
    [自我呈现Modalviewcontroller:imgController动画:是]

    尝试同时从
    plist
    文件中删除状态栏设置,并将以下内容添加到
    AppDelegate的
    应用程序的IDFinishLaunchwithOptions:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
     [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];
    }
    
    更新:

    试试这个

    -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    switch (buttonIndex)
    {
        case 0: 
        {
    
            imgController = [[UIImagePickerController alloc] init];
            imgController.allowsEditing = YES;
            imgController.sourceType =  UIImagePickerControllerSourceTypeCamera;   
            imgController.delegate=self;
            [self presentModalViewController:imgController animated:YES];
    
        } 
        case 1:
        {
            imgController = [[UIImagePickerController alloc] init];
            imgController.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
            imgController.delegate=self;
            [self presentModalViewController:imgController animated:YES];  
        }
    }
    } 
    

    稍微晚了一点,但是UIViewController正在调用什么
    presentModalViewController:animated:
    UIPopoverController
    的孩子吗?如果是这样的话,那就是造成这种情况的原因。试着从弹出窗口parentViewController调用它

    试试下面的代码,它对我来说非常有用

    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:   (NSInteger)buttonIndex
    {
    if(buttonIndex==0)
        {
        [self takePhoto];
    
        }
    else if(buttonIndex==1)
        {
        [self choosePhoto];
        }
    }
    
    
    -(void)takePhoto
    {
    UIDevice *device = [UIDevice currentDevice];
    
    NSString *currDevice = [device model];
    
    NSLog(@"device is %@",currDevice);
    
       if(![currDevice isEqualToString:@"iPhone Simulator"])
            {
           [[UIApplication sharedApplication]    setStatusBarOrientation:UIInterfaceOrientationPortrait];
        UIImagePickerController *imgPickerCon = [[UIImagePickerController alloc] init];
        imgPickerCon.sourceType = UIImagePickerControllerSourceTypeCamera;
        imgPickerCon.delegate = self;
        [self presentModalViewController:imgPickerCon animated:YES];
        [imgPickerCon release];
        imgPickerCon = nil;
        }
      else{
        UIAlertView *alrt=[[UIAlertView alloc] initWithTitle:@"Message" message:@"Camera Will Not Open in Simulator" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alrt show];
        [alrt release];
    }
     }
    
     -(void)choosePhoto
     {
    
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
    UIImagePickerController *imgPickerCon = [[UIImagePickerController alloc] init];     
    imgPickerCon.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imgPickerCon.delegate = self;
    [self presentModalViewController:imgPickerCon animated:YES];        
    [imgPickerCon release];
    imgPickerCon = nil;
      }
    
    
      - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [picker dismissModalViewControllerAnimated:YES];
     }
    
       - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)myimage editingInfo:(NSDictionary *)editingInfo 
      {
    
    
    [picker dismissModalViewControllerAnimated:YES];
    image=myimage;
    
    imgView.image=myimage;
    
      }
    

    对于iPad,建议您使用popover来显示MediaBrowser(照相机/照片库):

    您还可以设置popover的内容视图:

    ipc.delegate = self; 
    ipc.editing = NO;       
    ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    ipc.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:ipc.sourceType];
    
    [popOverController presentPopoverFromRect:btnGallery.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    

    正如您在阅读中指出的那样,简单的解决方案是在plist中添加一行,其中包含以下键值

    UIStatusBarStyle~ipad |字符串| UIStatusBarStyleBlack不透明

    这是一个解决方案,如果你不想在那里的代码上做太多的“脏活”,就让plist来完成工作


    但是,如果您不介意编写代码,您给出的解决方案将与我的建议相同。

    对不起。错过了。现在编辑。请检查。检查更新,这是我立即看到的唯一一件我会做得不同的事情。老实说,真的没有什么,但尝试并没有什么坏处。您的代码没有任何错误。不,我是在问,您做了什么更改?如果我添加了一个开关盒,则不使用if/else。试着用我写的东西替换你写的所有东西。它是从您的代码中编辑的,因此不会有任何内容被破坏。
    ipc.delegate = self; 
    ipc.editing = NO;       
    ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    ipc.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:ipc.sourceType];
    
    [popOverController presentPopoverFromRect:btnGallery.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];