Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Self-Destructing Message iPhone App Retrieving and Viewing Data from Parse.com Viewing Images Using UIImageView

Cristiano Di Marco
Cristiano Di Marco
5,345 Points

problem with prepareForSegue

I have a problem; the segue associated at the UIViewController of the imageView it doesn't work. When i click in the simulator in the cell with the message with an image, nothing happens. I have checked all the code in all the view controller and the cell identifier and segue identifier in the stoyboard too. i've checked the class name in the data browser of parse too. I use Xcode 5.1.1.

i Need help

2 Answers

Cristiano Di Marco
Cristiano Di Marco
5,345 Points

ok thanks!

inBoxViewController M

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { PFObject *message = [self.messages objectAtIndex:indexPath.row];

NSString *fileType = [message objectForKey:@"fileType"];

if ([fileType isEqualToString:@"image"]){

    [self performSegueWithIdentifier:@"showImage" sender:self];
    }
else {

}

}

  • (IBAction)logout:(id)sender { [PFUser logOut]; [self performSegueWithIdentifier:@"showLogin" sender:self]; }

  • (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; } }

imageViewController M

@implementation ImageViewController

  • (void)viewDidLoad { [super viewDidLoad];

    PFFile *imageFile = [self.message objectForKey:@"file"]; NSURL *imageFileUrl = [[NSURL alloc]initWithString:imageFile.url]; NSData *imageData = [NSData dataWithContentsOfURL:imageFileUrl]; self.imageView.image = [UIImage imageWithData:imageData];

}

Neil Shweky
Neil Shweky
5,022 Points

I would perform some kind of test to make sure that the method is being called. Maybe try putting a breakpoint there!

Cristiano Di Marco
Cristiano Di Marco
5,345 Points

Thank you Neil, but i've fixed it!!! I don't know how and i don't understand but now it works! Thank you!