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

Self destructing message

When i send a photo to myself on the iOS simulator, it won't show up in my inbox. Please help????

3 Answers

just because you send the photo doesnt mean its going to show up after you send it. You have to refresh the table view. Your view controller would have to get the messages again and reload the table data. Try sending a message, exiting the app (make sure you quit it, not just enter the background) and then open it again and see if the message shows up. In the implementing designs for iPhone course you implement pull to refresh which provides a solution to this sort of thing.

Thankyou for responding! But, i tried it still doesn't work. in parse the message shows up with recipient(s)-me but in Xcode in drop down tab it says retrieved 0 messages.

are you sure you are logged in as the user you sent the message to? does it do this with other users or just this one? can you post the code where you retrieve the messages?

import "InboxViewController.h"

import "ImageViewController.h"

@interface InboxViewController ()

@end

@implementation InboxViewController

  • (void)viewDidLoad { [super viewDidLoad];

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

  • (void)viewDidAppear:(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 *)ableView didSelectRowAtIndexPath:(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 {

    } }

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

i dont really see anything wrong with your code. if you want push it to githup or zip it and upload to dropbox and ill take a look at it