Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS UIImageView不显示图像_Ios_Objective C_Uinavigationcontroller_Uiimageview - Fatal编程技术网

iOS UIImageView不显示图像

iOS UIImageView不显示图像,ios,objective-c,uinavigationcontroller,uiimageview,Ios,Objective C,Uinavigationcontroller,Uiimageview,我的应用程序中有两个视图控制器,一个控制器使用AVCaptureSession捕捉照片 我在写这个, [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) { CFDictionaryRef exifAttachments = CMG

我的应用程序中有两个视图控制器,一个控制器使用AVCaptureSession捕捉照片

我在写这个,

[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
 {
     CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
     if (exifAttachments)
     {
         // Do something with the attachments.
         NSLog(@"attachements: %@", exifAttachments);
     }
     else
         NSLog(@"no attachments");

     NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
     UIImage *displayimage = [[UIImage alloc] initWithData:imageData];

     SecondViewController *sec = [[SecondViewController alloc]init];
     sec.showTakenPic.image = displayimage;
     [self.navigationController pushViewController:sec animated:YES];
 }];
SecondViewController包含UIImageView,我正在将其图像设置为显示图像,但未设置图像

我的第二个ViewController是由故事板制成的

第二个ViewController.h看起来像这样

#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController

@property(atomic,retain) IBOutlet UIImageView *showTakenPic;

@end
#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

-(void)viewDidLoad {
 [super viewDidLoad];
 [self.navigationController setNavigationBarHidden:YES animated:YES];
}

-(void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
图像在UIImageView中不可见为什么?

试试这个

您必须首先从情节提要加载控制器

根据此图像设置标识符

然后

这是主线问题

Choice-2

if (imageData)
{
 UIImage *displayimage = [[UIImage alloc] initWithData:imageData];

 SecondViewController *sec = [[SecondViewController alloc]init];
 sec.showTakenPic.image = displayimage;
 [self.navigationController pushViewController:sec animated:YES];
}
试试这个

您必须首先从情节提要加载控制器

根据此图像设置标识符

然后

这是主线问题

Choice-2

if (imageData)
{
 UIImage *displayimage = [[UIImage alloc] initWithData:imageData];

 SecondViewController *sec = [[SecondViewController alloc]init];
 sec.showTakenPic.image = displayimage;
 [self.navigationController pushViewController:sec animated:YES];
}

首先,检查图像是否为非零。 第二,在按下视图控制器后尝试设置图像

if (displayimage)
{
     SecondViewController *sec = [[SecondViewController alloc]init];
     [self.navigationController pushViewController:sec animated:YES];
     sec.showTakenPic.image = displayimage;
     sec.showTakenPic.backgroundColor = [UIColor redColor];
}
else
{
    NSLog(@"displayimage is nill");
}
FirstViewController.m

SecondViewController *postImageViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

[postImageViewController setImage:image];

SecondViewController.h

@interface SecondViewController : UIViewController {

    UIImage * postImage;
}

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

- (void)setImage:(UIImage*)image;

@end

SecondViewController.m

- (void)viewWillAppear:(BOOL)animated {

    if(postImage) {

        _imageView.image = postImage;

    }

}

- (void)setImage:(UIImage*)image {

    postImage = image;

}

首先,检查图像是否为非零。 第二,在按下视图控制器后尝试设置图像

if (displayimage)
{
     SecondViewController *sec = [[SecondViewController alloc]init];
     [self.navigationController pushViewController:sec animated:YES];
     sec.showTakenPic.image = displayimage;
     sec.showTakenPic.backgroundColor = [UIColor redColor];
}
else
{
    NSLog(@"displayimage is nill");
}
FirstViewController.m

SecondViewController *postImageViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

[postImageViewController setImage:image];

SecondViewController.h

@interface SecondViewController : UIViewController {

    UIImage * postImage;
}

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

- (void)setImage:(UIImage*)image;

@end

SecondViewController.m

- (void)viewWillAppear:(BOOL)animated {

    if(postImage) {

        _imageView.image = postImage;

    }

}

- (void)setImage:(UIImage*)image {

    postImage = image;

}

图像有多大?它是什么颜色?如果图像比UIImageView大得多,并且ContentMode属性设置不正确,则您可能只能看到图像的一小部分黑色。

图像有多大,颜色是什么?如果图像比UIImageView大得多,并且ContentMode属性设置不正确,则您可能只看到图像的一小部分黑色。

在内存中加载SecondViewController时尝试设置图像。。获取UIImage类型的ivar,当控制器推入堆栈时,使用ivar在showTakenPic imageView上设置图像

UIStoryboard mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];
 SecondViewController *controller = (SecondViewController *)  
[mainStoryboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
controller.imageToSet = imagePickedFromFirstController
[self.navigationController pushViewController:controller];
您可以将此代码添加到SecondViewController的viewDidLoad或ViewWillDisplay中

self.showTakenPic.image = self.imageToSet

或者你用的任何东西

在内存中加载SecondViewController时尝试设置图像。。获取UIImage类型的ivar,当控制器推入堆栈时,使用ivar在showTakenPic imageView上设置图像

UIStoryboard mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];
 SecondViewController *controller = (SecondViewController *)  
[mainStoryboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
controller.imageToSet = imagePickedFromFirstController
[self.navigationController pushViewController:controller];
您可以将此代码添加到SecondViewController的viewDidLoad或ViewWillDisplay中

self.showTakenPic.image = self.imageToSet

或者你用的任何东西

您应该将图像间接设置到第二个视图控制器中

if (displayimage)
{
     SecondViewController *sec = [[SecondViewController alloc]init];
     [self.navigationController pushViewController:sec animated:YES];
     sec.showTakenPic.image = displayimage;
     sec.showTakenPic.backgroundColor = [UIColor redColor];
}
else
{
    NSLog(@"displayimage is nill");
}
FirstViewController.m

SecondViewController *postImageViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

[postImageViewController setImage:image];

SecondViewController.h

@interface SecondViewController : UIViewController {

    UIImage * postImage;
}

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

- (void)setImage:(UIImage*)image;

@end

SecondViewController.m

- (void)viewWillAppear:(BOOL)animated {

    if(postImage) {

        _imageView.image = postImage;

    }

}

- (void)setImage:(UIImage*)image {

    postImage = image;

}

您应该将图像间接设置到第二个视图控制器中

if (displayimage)
{
     SecondViewController *sec = [[SecondViewController alloc]init];
     [self.navigationController pushViewController:sec animated:YES];
     sec.showTakenPic.image = displayimage;
     sec.showTakenPic.backgroundColor = [UIColor redColor];
}
else
{
    NSLog(@"displayimage is nill");
}
FirstViewController.m

SecondViewController *postImageViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

[postImageViewController setImage:image];

SecondViewController.h

@interface SecondViewController : UIViewController {

    UIImage * postImage;
}

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

- (void)setImage:(UIImage*)image;

@end

SecondViewController.m

- (void)viewWillAppear:(BOOL)animated {

    if(postImage) {

        _imageView.image = postImage;

    }

}

- (void)setImage:(UIImage*)image {

    postImage = image;

}

@Anbu Karthik先生showTakenPic是IBOutlet他必须从情节提要加载我同意你的观点,也考虑一下这个场景,在
imageData
转换之前,页面也将导航图像不显示。第二视图控制器不是导航控制器,所以我可以像这样推它吗?@avinashharma您可以推它,但脚本中的实例化是compulsary@Anbu.Karthik同意,长官,但如果没有图像,仍在从nib加载compulsary@Anbu.Karthik先生,showTakenPic是IBOutlet,他必须从情节提要加载我同意你的观点,也考虑一下这个场景,在
imageData
转换之前,页面也将导航图像不显示。第二视图控制器不是导航控制器,所以我可以像这样推它吗?@avinashharma您可以推它,但脚本中的实例化是compulsary@Anbu.Karthik同意,长官,但如果没有图像,仍然从nib加载是强制的显示图像不是nil但即使在设置图像UIImageView显示nilYes仍然给我一个黑屏显示图像不是nil但即使在设置图像UIImageView显示nilYes仍然给我一个黑屏