5

我有一个UIActionSheetiPad 版,它有三个选项:

  1. 取消
  2. 相机
  3. 照片库

当我触摸“照片库”选项时,我得到一个崩溃和一条消息

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];  
}
}  

我在最后一行崩溃了,即[self presentModalViewController:imgController animated:YES];

4

5 回答 5

10

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

UIImagePickerController *ipc = [[UIImagePickerController alloc] init];

UIPopoverController *popOverController = [[UIPopoverController alloc] initWithContentViewController:ipc];
popOverController.delegate = self;

您还可以设置弹出框的内容视图:

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];
于 2012-07-20T13:08:38.387 回答
1

试试下面的代码它对我来说很完美

- (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;

  }
于 2012-07-18T12:24:41.080 回答
0

Try removing your status bar settings from the plist file all together and adding the following to your AppDelegate's applicationDidFinishLaunchingWithOptions:

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

UPDATE:

Try this

-(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];  
    }
}
} 
于 2012-04-02T05:25:42.933 回答
0

有点晚了,但是 UIViewController 什么叫presentModalViewController:animated:a 的孩子UIPopoverController?如果是这样,那就是造成这种情况的原因。尝试从弹出框 parentViewController 调用它

于 2012-05-05T14:11:33.743 回答
0

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

UIStatusBarStyle~ipad | 字符串 | UIStatusBarStyle黑色不透明

(此处图片中的第三行,抱歉,我现在还不能发布图片)

如果您不想对那里的代码做太多“肮脏的工作”,这是解决方案之一,只需将其留给 plist 即可完成工作。

但是如果你不介意写代码,VSN给出的解决方案会和我的建议一样。

于 2013-01-25T15:37:39.243 回答