I am attempting to pass a variable between to view controllers and then show the new view
I have implemented the following code to pass a variable (without using segue)
viewCameraViewController *viewCamera = [[viewCameraViewController alloc] initWithNibName:@"viewCameraViewController" bundle:nil];
viewCamera.str1 = self.str;
[self.navigationController pushViewController:viewCamera animated:YES];
and then this to show the view
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"cameraView"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
however when the new view loads the variable is null
here is my viewCamera class
//
// viewCameraViewController.m
// WebView
//
// Created by Admin on 31/10/2015.
// Copyright (c) 2015 Admin. All rights reserved.
//
#import "viewCameraViewController.h"
@interface viewCameraViewController ()
@end
@implementation viewCameraViewController
- (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)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)takePhoto:(UIButton *)sender {
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device has no camera"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[myAlertView show];
} else {
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController: picker animated:YES completion:NULL];
}
}
-(IBAction)selectPhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController: picker animated:YES completion:NULL];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
@end
im assuming that this is caused by initialising two instances of the class, one called viewCamera and the other called VC.
can anyone help identify where i am going wrong here and point me in the right direction.
Thanks in advance