iPad有UIActionSheet
,有三个选项:
当我触摸“照片库”选项时,我收到了崩溃和消息
此设备无法使用UIStatusBarStyleBlackTranslucent。
我读过this post,但没弄明白。
有人能帮助我吗?
更新:
-(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];
答案 0 :(得分:10)
对于iPad,建议您使用popover来呈现MediaBrowser(相机/ photoLibrary):
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
UIPopoverController *popOverController = [[UIPopoverController alloc] initWithContentViewController:ipc];
popOverController.delegate = self;
您还可以设置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];
答案 1 :(得分: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;
}
答案 2 :(得分:0)
尝试从plist
文件中一起删除状态栏设置,并将以下内容添加到AppDelegate's
applicationDidFinishLaunchingWithOptions:
- (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];
}
}
}
答案 3 :(得分:0)
有点晚了,但是UIViewController最近调用presentModalViewController:animated:
是UIPopoverController
的孩子吗?如果是这样,那就是造成这种情况的原因。尝试从popovers parentViewController
答案 4 :(得分:0)
就像你用the post指出的那样,你已经阅读了,简单的解决方案就是在plist中添加一行,其中包含以下键值
UIStatusBarStyle~ipad |字符串| UIStatusBarStyleBlackOpaque
(3rd row in the picture here, sorry cause I can't post image yet now)
如果你不想对那里的代码做太多“肮脏的工作”,这就是解决方案之一,只需将它留给plist来完成工作。
但如果您不介意编写代码,VSN给出的解决方案将与我的建议相同。