Ok, so I'm relatively new to xcode and have hit a dead end on this particular topic. I'm not too sure what code I need.
I am currently trying to force a segue (using storyboards) from one View Controller to another View Controller. Once the user has selected an image using UIImagePickerController the picker dismisses itself leaving the selected image in the ImageView.
However once the picker dismisses itself I then want to perform a segue that recognizes that this has occurred and then sends the image in the ImageView to the new View Controller.
Heres my code so far (Ive annotated the bits I'm stuck on)
Code:
@implementation SantaViewController
@synthesize imageView,choosePhotoBtn, takePhotoBtn;
- (void)viewDidLoad {
if (![UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera]) {
takePhotoBtn.hidden = YES;
}
}
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
// This is where i need to place the identifier.
// The Identifier needs to be the picker dismissing itself and leaving an image in ImageView.
{
[self performSegueWithIdentifier:@"homeEdit" sender:sender];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"homeEdit"])
{
SantaViewController2 *viewController = segue.destinationViewController;
[viewController //pass imageView to the destination View Controller code. ];
}
Any help would be greatly appreciated guys and sorry if its an easy answer that I've missed.
Did you ever solve this problem? I am facing a similar issue and any help would be appreciated.
THANKS!
You should watch the 2011 WWDC video session on Storyboard. They explain this specifically.
There is also info in the documentation on storyboards that tells you what to do:
Quote:
Preparing to Transition to a New View Controller
Whenever a user triggers a segue in the current scene, the storyboard runtime calls the prepareForSegue:sender: method of the current view controller. This method gives the current view controller an opportunity to pass any needed data to the view controller that is about to be displayed. When implementing your view controller classes, you should override this method and use it to handle these transitions.
The key bit is in bold. You need to use the method prepareForSegue:sender:
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
I am stuck trying to figure out the same scenario.
I read in one place that the UIImagePicker is not available in storyboards and had to be brought in via core data...helper class.
I would love to know how to make this work without all that.
I just want to do what chrisb was trying.
Within a view controller goto photo library, pick an image and have it stay in an image view on that view controller window.
I am stuck trying to figure out the same scenario.
I read in one place that the UIImagePicker is not available in storyboards and had to be brought in via core data...helper class.
I would love to know how to make this work without all that.
I just want to do what chrisb was trying.
Within a view controller goto photo library, pick an image and have it stay in an image view on that view controller window.
I am using Xcode 4.2
Anyone who could explain this?
R
I've never tried to save an image picker in a nibfile or a storyboard. I don't think it's available in either
When I need one, I just create one and invoke it in code. It's only a couple of lines of code.
Loading an image picker from Core Data makes no sense whatsoever. Core data is for saving app data, not view objects. You've got your information mixed up.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
but it boils down to the fact that it's not available in storyboards.
What I am trying to to is create a deep tableview ap in storyboards, where at the bottom level there is a model view that has details like ingredients, notes, and the means to take a photo or select photo from the photo library and have it assigned to an image view on that view and as a cell detail image. I have all of it done accept for this missing functionality.
I'd be grateful to know what the few lines of code are to solve (getting the camera functions image picker fuinction in my layout ) this and not have to keep messing around with augmenting tutorials I find everywhere.
please enlighten me.
Last edited by Rynow; 05-16-2012 at 10:45 PM.
Reason: Added details
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Once you've segued, you can reference the calling view controller by navigating your encompassing view controllers. For example, if your view controllers are embedded in a UINavigationController, you could do this in your destination view controller's viewWillAppear:
Assuming that the calling view controller was the first in the navigation stack. You could then reference svc.imageView to get the calling imageView. (Note that I'm not at my Mac and haven't syntax-checked this code.)
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.