So I've had a few different problems with this app, its my first app and never coded before, first was I couldn't get my button to open a "secondviewcontroller" to display my image, thinks i fixed that now, now when my button loads my "secondviewcontroller" it opens the camera roll I select an image and then it closes and reopens the camera roll to reselect another image.
This is my FirstViewController.h - its calledBESPOKEViewController.h
#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
@interface BESPOKEViewController : UIViewController
<UIImagePickerControllerDelegate,
UINavigationControllerDelegate>
@property BOOL newMedia;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
- (void)useCamera:(id)sender;
- (void)useCameraRoll:(id)sender;
@end
BESPOKEViewController.m
#import "BESPOKEViewController.h"
@interface BESPOKEViewController ()
@end
@implementation BESPOKEViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction) useCamera:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker
animated:YES completion:nil];
_newMedia = YES;
}
}
- (IBAction) useCameraRoll:(id)sender{}
@end
This is my SecondViewController.h - its called secondpage.h
@interface secondpage : UIViewController
<UIImagePickerControllerDelegate,
UINavigationControllerDelegate>
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@end
secondpage.m
#import "secondpage.h"
@interface secondpage ()
@end
@implementation secondpage
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
// method call
[self openGallery];
}
-(void) openGallery {
UIImagePickerController *imagePicker;
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:NO completion:^{
}];
}
- (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:^{
}];
// change the name of imageview here your way
self.imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
updated to all code just not source from storyboard, would Thank you in advance