从相册中挑选图像后导航栏不显示

时间:2013-07-03 10:08:52

标签: iphone uinavigationcontroller uiimageview photo-gallery

我有从相册中挑选图片的按钮。选择图像后,我需要显示navigationBar和分享按钮。但是在选择图像后,navigationBar没有显示。我用`[self.navigationController.navigationBar setHidden:NO] ;.但导航栏没有显示。

代码:

-(void)showAlbum:(id)sender{

    imagePicker=[[UIImagePickerController alloc]init];

    imagePicker.delegate = self;

    imagePicker.allowsEditing =NO;

    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:imagePicker animated:YES];

}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    //release picker
    [picker dismissModalViewControllerAnimated:YES];

 }

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    //set image

    [self.navigationController.navigationBar setHidden:NO];

   newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];

    [newImage setFrame:CGRectMake(0, 0, 320, 568)];

[self.view addSubview:newImage];

  [picker dismissModalViewControllerAnimated:YES];

}

2 个答案:

答案 0 :(得分:1)

只需在dismissModalViewController

之后隐藏导航栏
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    //set image

   newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];

    [newImage setFrame:CGRectMake(0, 0, 320, 568)];

[self.view addSubview:newImage];

  [picker dismissModalViewControllerAnimated:YES];
[self.navigationController.navigationBar setHidden:NO];
}  

或者将其放在viewWillAppear中,因为这会在dismiss ModalViewController后调用

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [self.navigationController.navigationBar setHidden:NO];
}

答案 1 :(得分:0)

在您要呈现ImagePicker控制器的视图中,请添加

[self.navigationController.navigationBar setHidden:NO];
ViewWillAppear方法中的

。我认为这可能是个问题。请及时通知我。