Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

marsela meco
marsela meco
511 Points

Self destructing message app

On the simulator, i click the received message on inboxViewController BUT nothing happens-it won't go on to the imageViewController so i can see the image., i set the segue and created the image files and all that??? am i supposed to change or add something?? what do i do?

Stone Preston
Stone Preston
42,016 Points

Can you please post your code for your inbox view controller.

marsela meco
marsela meco
511 Points

import "InboxViewController.h"

import "ImageViewController.h"

@interface InboxViewController ()

@end

@implementation InboxViewController

  • (void)viewDidLoad { [super viewDidLoad];

    self.moviePlayer = [[MPMoviePlayerController alloc] init];

    PFUser *currentUser = [PFUser currentUser]; if (currentUser) { NSLog(@"Current user: %@", currentUser.username); } else { [self performSegueWithIdentifier:@"showLogin" sender:self]; } }

  • (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated];

    PFQuery *query = [PFQuery queryWithClassName:@"Messages"]; [query whereKey:@"recipientsIds" equalTo:[[PFUser currentUser] objectId]]; [query orderByDescending:@"createdAt"]; [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (error) { NSLog(@"Error: %@ %@", error, [error userInfo]); } else { // We found messages! self.messages = objects; [self.tableView reloadData]; NSLog(@"Retrieved %d messages", [self.messages count]); } }]; }

pragma mark - Table view data source

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; }

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return [self.messages count]; }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    PFObject *message = [self.messages objectAtIndex:indexPath.row]; cell.textLabel.text = [message objectForKey:@"senderName"];

    NSString *fileType = [message objectForKey:@"fileType"]; if ([fileType isEqualToString:@"image"]) { cell.imageView.image = [UIImage imageNamed:@"icon_image"]; } else { cell.imageView.image = [UIImage imageNamed:@"icon_video"]; }

    return cell; }

pragma mark - Table view delegate

  • (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *) indexPath { self.selectedMessage = [self.messages objectAtIndex:indexPath.row]; NSString *fileType = [self.selectedMessage objectForKey:@"fileType"]; if ([fileType isEqualToString:@"image"]) { [self performSegueWithIdentifier:@"showImage" sender:self]; } else { // File type is video PFFile *videoFile = [self.selectedMessage objectForKey:@"file"]; NSURL *fielUrl = [NSURL URLWithString:videoFile.url]; self.moviePlayer.contentURL = fielUrl; [self.moviePlayer prepareToPlay]; [self.moviePlayer thumbnailImageAtTime:0 timeOption: MPMovieTimeOptionNearestKeyFrame];

    // Add it to the view controller so we can see it
    [self.view addSubview:self.moviePlayer.view];
    [self.moviePlayer setFullscreen:YES animated:YES];
    

    }

    // Delete it! NSMutableArray *recipientsIds = [NSMutableArray arrayWithArray:[self.selectedMessage objectForKey:@"recipientIds"]];

    if ([recipientsIds count] == 1) { // Last recipient - delete! [self.selectedMessage deleteInBackground]; } else { // Remove the recipient and save it [recipientsIds removeObject:[[PFUser currentUser] objectId]]; [self.selectedMessage setObject:recipientsIds forKey:@"recipientIds"]; [self.selectedMessage saveInBackground]; } }

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

@end

AND inbox.h

import <UIKit/UIKit.h>

import <Parse/Parse.h>

import <MediaPlayer/MediaPlayer.h>>

@interface InboxViewController : UITableViewController

  • (IBAction)logout:(id)sender;

@property (nonatomic, strong) NSArray *messages; @property (nonatomic, strong) PFObject *selectedMessage; @property (nonatomic, strong) MPMoviePlayerController *moviePlayer;

@end

9 Answers

marsela meco
marsela meco
511 Points

2014-01-20 13:42:17.735 Vista[9037:70b] Current user: marsela meco 2014-01-20 13:42:18.209 Vista[9037:70b] Retrieved 4 messages 2014-01-20 13:42:19.189 Vista[9037:70b] Could not load the "Username" image referenced from a nib in the bundle with identifier "Meco-INC..Vista" 2014-01-20 13:42:29.668 Vista[9037:70b] Retrieved 4 messages THIS IS ERROR WHEN I CLICK ON MESSAGE IN MY INBOX

Stone Preston
Stone Preston
42,016 Points

are you sure you are calling performSegueWithIdentifier in the tableView delegate method didSelectRowAtIndexPath? Double check that you used the same segue identifier as is set in your storyboard.

Stone Preston
Stone Preston
42,016 Points

from your code it looks like you implemented didDeselectRowAtIndexPath instead of didSelectRowAtIndexPath. try changing that to the right method and see if it works

marsela meco
marsela meco
511 Points

OK, i fixed everything EXCEPT for the simulator not showing me my image when i select one in my inbox, i triple checked everything in inbox.m and image.m and .h's???? I need Help now??:)

marsela meco
marsela meco
511 Points

2014-01-20 12:36:09.222 Vista[8101:70b] Current user: Erdi Meco 2014-01-20 12:36:09.780 Vista[8101:70b] Retrieved 2 messages 2014-01-20 12:36:15.533 Vista[8101:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initWithString:relativeToURL:]: nil string parameter' *** First throw call stack: ( 0 CoreFoundation 0x028d25e4 exceptionPreprocess + 180 1 libobjc.A.dylib 0x026558b6 objc_exception_throw + 44 2 CoreFoundation 0x028d23bb +[NSException raise:format:] + 139 3 Foundation 0x022781c0 -[NSURL(NSURL) initWithString:relativeToURL:] + 89 4 Foundation 0x022da7aa -[NSURL(NSURL) initWithString:] + 48 5 Vista 0x000081e8 -[ImageViewController viewDidLoad] + 248 6 UIKit 0x014d7318 -[UIViewController loadViewIfRequired] + 696 7 UIKit 0x014d75b4 -[UIViewController view] + 35 8 UIKit 0x014f13e2 -[UINavigationController _startCustomTransition:] + 778 9 UIKit 0x014fe0c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688 10 UIKit 0x014fecb9 -[UINavigationController __viewWillLayoutSubviews] + 57 11 UIKit 0x01638181 -[UILayoutContainerView layoutSubviews] + 213 12 UIKit 0x0142e267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355 13 libobjc.A.dylib 0x0266781f -[NSObject performSelector:withObject:] + 70 14 QuartzCore 0x006b92ea -[CALayer layoutSublayers] + 148 15 QuartzCore 0x006ad0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 16 QuartzCore 0x006acf40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26 17 QuartzCore 0x00614ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294 18 QuartzCore 0x00615e71 _ZN2CA11Transaction6commitEv + 393 19 QuartzCore 0x00616544 _ZN2CA11Transaction17observer_callbackEP19CFRunLoopObservermPv + 92 20 CoreFoundation 0x0289a4ce CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30 21 CoreFoundation 0x0289a41f __CFRunLoopDoObservers + 399 22 CoreFoundation 0x02878344 __CFRunLoopRun + 1076 23 CoreFoundation 0x02877ac3 CFRunLoopRunSpecific + 467 24 CoreFoundation 0x028778db CFRunLoopRunInMode + 123 25 GraphicsServices 0x032a09e2 GSEventRunModal + 192 26 GraphicsServices 0x032a0809 GSEventRun + 104 27 UIKit 0x013c3d3b UIApplicationMain + 1225 28 Vista 0x0000698d main + 141 29 libdyld.dylib 0x0481870d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

I GET THIS ERROR WHEN I CLICK BOTH MESSAGES IN MY INBOX???

Stone Preston
Stone Preston
42,016 Points

set an exception breakpoint in your project by going to debug -> breakpoints -> add exception breakpoint. This will allow you to see which line of code in your project is throwing the exception.

marsela meco
marsela meco
511 Points

on the same project, its all good, BUT now in simulator, i send a message picture to myself, but it won't show up in my inbox as it had been doing, might i have deleted something accidentally????

marsela meco
marsela meco
511 Points

/Users/erdimeco/Desktop/Vista/Vista/InboxViewController.m:100:27: 'thumbnailImageAtTime:timeOption:' is deprecated: first deprecated in iOS 7.0 Is this a problem too

Stone Preston
Stone Preston
42,016 Points

you can ignore that for now, its not what is causing your problems.

marsela meco
marsela meco
511 Points

Ok i fixed my problems, EXCEPT now is still can't view my image in simulator when i click on a message in my inbox, i checked everything like the inbox.m and image.m files along with .h's ???? I need Help now???:):)

marsela meco
marsela meco
511 Points

2014-01-20 13:42:17.735 Vista[9037:70b] Current user: marsela meco 2014-01-20 13:42:18.209 Vista[9037:70b] Retrieved 4 messages 2014-01-20 13:42:19.189 Vista[9037:70b] Could not load the "Username" image referenced from a nib in the bundle with identifier "Meco-INC..Vista" 2014-01-20 13:42:29.668 Vista[9037:70b] Retrieved 4 messages THIS IS ERROR WHEN I CLICK ON MESSAGE IN MY INBOX