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 Build a Self-Destructing Message iPhone App Retrieving and Viewing Data from Parse.com Deleting Data from Parse.com

Ribbit - question about multiple users.

Im not sure if this is just a problem for me or if this is just how the app is supposed to function, but I notice that only one user can edit friends.

For example, if I login and edit my friend list, this friends list exists on all other users. Other users do not have the ability to edit the friend list, only the initial user.

Is this executing in the "correct" manner?

2 Answers

Stone Preston
Stone Preston
42,016 Points

i dont think the videos make an attempt to fix this (they may though). what you need to happen on logout is your friends array that populates the tableView need to be nil and the currentUser needs to be reset to nil. Currently this doesnt happen. the user logs out, then someone else logs in, and the same data is displayed because the currentUser and array still hold the data for the previous user.

One way to do this is using the notification center. if you post the code for your view controller I can give you a more definitive answer

Vetri Selvi Vairamuthu
Vetri Selvi Vairamuthu
1,353 Points

Stone Preston Can you help me out? I'm facing the same issue. Couldn't figure it out! //InboxViewControllerTableViewController.m

import "InboxViewControllerTableViewController.h"

import "ImageViewController.h"

import "FriendsViewControllerTableViewController.h"

@interface InboxViewControllerTableViewController ()

@end

@implementation InboxViewControllerTableViewController

  • (void)viewDidLoad { [super viewDidLoad]; self.videoMessage = [[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:@"recipientsId" equalTo:[[PFUser currentUser]objectId]]; [query orderByDescending:@"createdAt"]; [query findObjectsInBackgroundWithBlock:^(NSArray * objects, NSError *error) { if(error){ NSLog(@"Error: %@%@",error , [error userInfo]);

    }
    else{
        self.messages = objects;
       // NSLog(@"Checker 1 %@",self.messages);
       // NSLog(@"Checker 2 %@",objects);
        [self.tableView reloadData];

    }
}];

}

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]; }

//copied from the blog.teamtreehouse -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.selectedMessages = [self.messages objectAtIndex:indexPath.row]; NSString *fileType = [self.selectedMessages objectForKey:@"fileType"]; //NSLog(@"filetype is %@",fileType); if ([fileType isEqualToString:@"image"]) { [self performSegueWithIdentifier:@"showImage" sender:self]; } else { // if it is video PFFile *file = [self.selectedMessages objectForKey:@"file"]; NSURL *fileURL = [NSURL URLWithString:file.url]; self.videoMessage.contentURL = fileURL; [self.videoMessage prepareToPlay]; // [self.videoMessage thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame]; [self.view addSubview:self.videoMessage.view]; [self.videoMessage play]; [self.videoMessage setFullscreen:YES animated:YES];

}
//Delete the messages :D

NSMutableArray *recipientsId = [NSMutableArray arrayWithArray:[self.selectedMessages objectForKey:@"recipientsId"]];
 NSLog(@"Recipients Ids : : %@",recipientsId);
if ([recipientsId count]==1) {
    // If the # of recipients is one, then we can delete message from the backend
    [self.selectedMessages deleteInBackground];


}
else{ //Delete this recipient from the recipients' list
    [recipientsId removeObject:[[PFUser currentUser]objectId]];

    [self.selectedMessages setObject:recipientsId forKey:@"recipientsId"];
    [self.selectedMessages saveInBackground];
}

}

  • (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"]; //cell.detailTextLabel.text = [message objectForKey:@"createdAt"];

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

    return cell;
    

}

  • (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.selectedMessages;

}

} @end