Passing image from one view to another

后端 未结 3 1394
迷失自我
迷失自我 2021-01-01 02:54

I\'m getting an image from the user from the photo gallery, and I want to pass it to a another view...

I\'ve read that I should be able to simply do something like t

相关标签:
3条回答
  • 2021-01-01 03:06

    First Viewcontroller:

    -(void)passimage
    {
        Second_ViewController *select_main = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"Second_ViewController"];
        select_main.tt_image = _bg_imageview.image;
        [[self navigationController]  pushViewController:select_main animated:YES];
    }
    

    Second Viewcontroller pass UIImage object:

    - (void)viewDidLoad {
    
        _bg_imageview.image = _bb_image;
    }
    
    0 讨论(0)
  • 2021-01-01 03:13

    I think I found the problem :

    In your class secondView, your UIImageView is not connected to the object UIImageView in the nib file.

    You should have something like that :

    IBOutlet UIImageView *imgView;
    

    To check if the view is correctly connected to the Nib you can do this :

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
            [imgView setBackgroundColor:[UIColor redColor]];
        }
        return self;
    }
    

    Your problem is interesting please let me know if it doesn't work I'll check deeper.

    0 讨论(0)
  • 2021-01-01 03:14

    This solved the issue:

    -(IBAction)sendImage:(id)sender
    {
        if(self.secondView == nil)
        {
            SecondView *secView = [[SecondView alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
    
            self.secondView = secView;
    
            secView.theImage = selectedImage.image;
        }
    
        [self.navigationController pushViewController:secondView animated:YES];
    }
    

    SecondView:

    @interface SecondView : UIViewController
    {
        UIImageView *imgView;
        UIImage *theImage;
    }
    
    @property (nonatomic, retain) IBOutlet UIImageView *imgView;
    @property (nonatomic, retain) UIImage *theImage;
    
    -(void)setImage:(UIImage *)image;
    
    @end
    

    and in the .m of secondView:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
        [imgView setImage:theImage];
    }
    
    0 讨论(0)
提交回复
热议问题