I have a UIButton that, when I click on it, pushes another view controller, but it crashes here
textViewController.message = self.selectedMessage; with error set message.
This is my button with code and method where it crashes:
- (IBAction)image:(id)sender {
[self performSegueWithIdentifier:#"image" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showLogin"]) {
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
} else {
[segue.identifier isEqualToString:#"showImage"];
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
ImageViewController *imageViewController = (ImageViewController *)segue.destinationViewController;
imageViewController.message = self.selectedMessage;
}
}
How can I fix the PrepareForSegue method so I can go to next VC when I press button. I put exception break point and it crashes at imageViewController.message = self.selectedMessage;. when I comment that line out everything works fine.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showLogin"]) {
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
} else {
ImageViewController *imageViewController = (ImageViewController *)segue.destinationViewController;
[imageViewController setHidesBottomBarWhenPushed:YES];
imageViewController.message = self.selectedMessage;
}
}
Try this .
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showLogin"]) {
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
} else {
[segue.identifier isEqualToString:#"showImage"];
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
ImageViewController *imageViewController = (ImageViewController *)segue.destinationViewController;
imageViewController.message = self.selectedMessage;
}
}
had to change it to this for it to work
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showLogin"]) {
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
} else if ([segue.identifier isEqualToString:#"showImage"]){
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
ImageViewController *imageViewController = (ImageViewController *)segue.destinationViewController;
imageViewController.message = self.selectedMessage;
}
}
Related
when I come the part of sending image from UICollectionViewController to another ViewController here is View A:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Detail Segue"])
{
PhotoDetailViewController *PhotoDetailVC = segue.destinationViewController;
NSIndexPath *path = [[self.collectionView indexPathsForSelectedItems] lastObject];
Photo *selectedPhoto = self.photos[path.row];
PhotoDetailVC.photo = selectedPhoto;
}
}
and I receive it in the ViewController (View B) using:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.imageView.image= self.photo.image;
}
I think the problem is that you didn't call performSegueWithIdentifier:sender: in any place in code which actually responsible for triggering navigation not prepareForSegue:sender: which is called when preparing for the navigation
so I suggest to implement collectionView:didSelectItemAtIndexPath: as the following
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
Photo *selectedPhoto = self.photos[path.row];
// this line is the one that is responsible for navigation
[self performSegueWithIdentifier:#"Detail Segue" sender:selectedPhoto];
}
and modify prepareForSegue:sender: as the following
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"Detail Segue"]) {
PhotoDetailViewController *PhotoDetailVC = segue.destinationViewController;
PhotoDetailVC.photo = sender;
}
}
I'm trying to send the captured image to another UIViewController.
So when I press captured button, it's taking a photo and I can save the image in my camera roll. But when I want to see image in another view I can't see it.
This is my code :
- (IBAction)captureButton:(id)sender
{
[self.cameraViewController captureImageWithCompletionHander:^(id data) {
self.image = ([data isKindOfClass:[NSData class]]) ? [UIImage imageWithData:data] : data;
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
[self performSegueWithIdentifier:#"savingSegue" sender:self];
}];
}
And this is the prepare for segue method.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"savingSegue"]) {
PhotoSaveViewController *pvc = [[PhotoSaveViewController alloc] init];
[pvc.imageView setImage:self.image];
}
}
If your second view is a PhotoSaveViewController then replace your prepareForSeque method with this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"savingSegue"]) {
PhotoSaveViewController *pvc = (PhotoSaveViewController *)segue.destinationViewController;
if (pvc)
[pvc.imageView setImage:self.image];
}
}
Indeed, it's not your job to instantiate the destination UIViewController, your UINavigationController have already done that.
I guess that imageView on PhotoSaveViewController it is outlet and it is not set at this moment. You should declare there some other property like
#property (nonatomic, retain) UIImage *inputImage;
and assign to that in prepareForSegue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"savingSegue"]) {
PhotoSaveViewController *pvc = segue.destinationViewController;
pvc.inputImage = self.image;
}
}
Then do the following in the PhotoSaveViewController:
- (void)viewDidLoad {
[super viewDidLoad];
self.imageView.image = self.inputImage;
}
Another approach you can create it from code totally. Assign Storyboard ID to the PhotoSaveViewController and then do the following:
- (IBAction)captureButton:(id)sender {
[self.cameraViewController captureImageWithCompletionHander:^(id data) {
self.image = ([data isKindOfClass:[NSData class]]) ? [UIImage imageWithData:data] : data;
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
PhotoSaveViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"PhotoSaveViewControllerID"];
dvc.inputImage = self.image;
[self.navigationController pushViewController:dvc animated:YES];
}];
}
I'm trying to make the buttons on a UIActionSheet call segues which go to other view controllers. This is the code i have so far and it just crashes. The error message i get is "'Receiver () has no segue with identifier 'Town''"
- (IBAction)CategorizeButton:(id)sender {
UIActionSheet* AS = [[UIActionSheet alloc]initWithTitle:#"Group by"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Town",#"Title",#"Location", nil];
[AS showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
[self performSegueWithIdentifier:#"Town" sender:self];
}
if (buttonIndex == 1)
{
[self performSegueWithIdentifier:#"Title" sender:self];
}
if (buttonIndex == 2)
{
[self performSegueWithIdentifier:#"Location" sender:self];
}
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSString* CategorizeTown = #"Town";
NSString* CategorizeTitle = #"Title";
NSString* CategorizeLocation = #"Location";
if ([[segue identifier] isEqualToString:CategorizeTown])
{
CategoryTableViewController* CAT = [segue destinationViewController];
// blah blah
}
if ([[segue identifier] isEqualToString:CategorizeTitle])
{
CategoryTableViewController* CAT = [segue destinationViewController];
// blah blah
}
if ([[segue identifier] isEqualToString:CategorizeLocation])
{
CategoryTableViewController* CAT = [segue destinationViewController];
// blah blah
}
}
In storyboard, select the segue.
Give it an identifier, (in your case, #"Town",#"Title",#"Location")
I cant able to pass the image from 1 view to another view in ios7.
in current view
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showRecipeDetail"]) {
BehindContributors *destViewController = segue.destinationViewController;
[destViewController setImage:#"1.jpg"];
}
in destination view
self.image1.image=self.image;
did you try imageNamed method on ÙIImage
like so;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showRecipeDetail"]) {
BehindContributors *destViewController = segue.destinationViewController;
[destViewController setImage:[UIImage imageNamed:#"1.jpg"]];
}
What are you trying to pass image name(i.e. NSString object) or image itself(i.e. UIImage object).
If you are passing image name then use following
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showRecipeDetail"]) {
BehindContributors *destViewController = segue.destinationViewController;
[destViewController setImageName:#"1.jpg"];
}
}
Destination view should have property imageName of NSString type
then use it as
self.imageView.image = [UIImage imageName:imageName];
If you are passing image then use following
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showRecipeDetail"]) {
BehindContributors *destViewController = segue.destinationViewController;
[destViewController setImageData:[UIImage imageNamed:#"1.jpg"]];
}
}
Destination view should have property imageData of UIImage type
then use it as
self.imageView.image = imageData;
I have a UIViewController, and i have to pass a value (UIImage, NSString) to an UINavigationViewController, I am using
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
AppDetail *advc = [segue destinationViewController];
if ([[segue identifier] isEqualToString:#"showDetail"]) {
advc.appTitel = name;
advc.appIcon = icon;
advc.detailAppName = detileName;
advc.appDescription = description;
advc.appDeveloper = developer;
}
}
to pass the value to the UIViewController, it works perfectly if I pass it directly to a UIViewController, but I can't pass it to a UINavigationViewController,
Anyone know how I can do this?
I have this sample code from an Apple segue example. Perhaps it helps.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Room Create"]) {
// Prepare the settings view where the user inputs the 'serviceType' and local peer 'displayName'
UINavigationController *navController = segue.destinationViewController;
SettingsViewController *viewController = (SettingsViewController *)navController.topViewController;
viewController.delegate = self;
// Pass the existing properties (if any) so the user can edit them.
viewController.displayName = self.displayName;
viewController.serviceType = self.serviceType;
}
}
To pass value using Segue in your case with a UINavigationController try the code below :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"])
{
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
AppDetail *advc = (AppDetail *)navController.topViewController;
advc.appTitel = name;
advc.appIcon = icon;
advc.detailAppName = detileName;
advc.appDescription = description;
advc.appDeveloper = developer;
}
}
If you don't use a UINavigationController, you need to use this following code :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"]) {
// Get reference to the destination view controller
AppDetail *advcc = segue.destinationViewController;
advc.appTitel = name;
advc.appIcon = icon;
advc.detailAppName = detileName;
advc.appDescription = description;
}
}