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
Kai Aldag
Courses Plus Student 13,560 PointsRecipients aren't showing up in Ribbit project
hey guys i need help on my Ribbit project the recipients aren't showing up in the select recipients screen. here the project: https://www.dropbox.com/sh/1csqrupe0gqbn2h/4gtbqculK7
thanks for any help possible, Kai.
Kai Aldag
Courses Plus Student 13,560 Pointsi dont think it's the camera because it worked perfectly until i started the uploading files sections for ribbit.
Stone Preston
42,016 Pointswell the camera view controller is where the users get added to the recipient selection list. The imagePicker controller is added to the camera view controller modally, and when you dismiss the picker you end up on the view for the camera view controller. So it probably is something wrong with your camera view controller, but not your imagePicker controller which is the actual camera.
Kai Aldag
Courses Plus Student 13,560 Pointsk here it is:
//
// CameraViewController.m
// Ribbit
//
// Created by kai don aldag on 2013-09-08.
// Copyright (c) 2013 kai.don.aldag. All rights reserved.
//
import "CameraViewController.h"
import <MobileCoreServices/UTCoreTypes.h>
@interface CameraViewController ()
@end
@implementation CameraViewController
- (void)viewDidLoad { [super viewDidLoad]; self.friendsRelation = [[PFUser currentUser] objectForKey:@"friendsRelation"]; self.ricipients = [[NSMutableArray alloc]init]; }
-(void) viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated];
PFQuery *query = [self.friendsRelation query];
[query orderByAscending:@"username"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(@" %@ %@", error, [error userInfo]);
}else{
self.friends = objects;
[self.tableView reloadData];
}
}];
if (self.image == nil && [self.videoFilePath length] == 0){
self.imagePicker = [[UIImagePickerController alloc]init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = NO;
self.imagePicker.videoMaximumDuration = 10;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}else{
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
}
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.friends count]; }
-
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
PFUser *user = [self.friends objectAtIndex:indexPath.row]; cell.textLabel.text = user.username;
if ([self.ricipients containsObject:user.objectId]){ cell.accessoryType = UITableViewCellAccessoryCheckmark; }else{ cell.accessoryType = UITableViewCellAccessoryNone; }
return cell; }
pragma mark - Table view delegate
-
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; PFUser *user = [self.friends objectAtIndex:indexPath.row];
if (cell.accessoryType == UITableViewCellAccessoryNone){ cell.accessoryType = UITableViewCellAccessoryCheckmark; [self.ricipients addObject:user.objectId]; } else { cell.accessoryType = UITableViewCellAccessoryNone; [self.ricipients removeObject:user.objectId]; } }
pragma mark - Image Picker Controller Delegate
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{ [self dismissViewControllerAnimated:NO completion:nil]; [self.tabBarController setSelectedIndex:0]; }
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *) kUTTypeImage]){
self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera){
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
}
}
else{
self.videoFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera){
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.videoFilePath)){
UISaveVideoAtPathToSavedPhotosAlbum(self.videoFilePath, nil, nil, nil);
}
}
}
[self dismissViewControllerAnimated:YES completion:nil]; }
pragma mark - IBActions
-
(IBAction)cancel:(id)sender { [self reset];
[self.tabBarController setSelectedIndex:0]; }
-
(IBAction)send:(id)sender { if (self.image == nil && [self.videoFilePath length]==0){ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:@"please capture or select a video or picture to share!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alertView show]; [self presentViewController:self.imagePicker animated:NO completion:nil]; }else{ [self uploadMessage];
[self.tabBarController setSelectedIndex:0];} }
pragma mark - helper methods
- (void)reset { self.image = nil; self.videoFilePath = nil; [self.ricipients removeAllObjects]; }
-(void) uploadMessage{
NSData *fileData;
NSString *fileName;
NSString *fileType;
if (self.image != nil) {
UIImage *newImage = [self resizeImage:self.image towidth:320.0f andHeight:480.0f];
fileData = UIImagePNGRepresentation(newImage);
fileName = @"image.png";
fileType = @"image";
}else{
fileData = [NSData dataWithContentsOfFile:self.videoFilePath];
fileName = @"video.mov";
fileType = @"video";
}
PFFile *file = [PFFile fileWithName:fileName data:fileData];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"an error occured!" message:@"please try sending your message again!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertView show];
}else {
PFObject *message = [PFObject objectWithClassName:@"Message"];
[message setObject:file forKey:@"file"];
[message setObject:fileType forKey:@"fileType"];
[message setObject:self.ricipients forKey:@"recipientsIds"];
[message setObject:[[PFUser currentUser] objectId] forKey:@"senderId"];
[message setObject:[[PFUser currentUser]username] forKey:@"senderName"];
[message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"an error occured!" message:@"please try sending your message again!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertView show];
}else{
[self reset];
}
}];
}
}];
}
-(UIImage *)resizeImage:(UIImage *)image towidth:(float)width andHeight:(float)height{ CGSize newSize = CGSizeMake(width, height); CGRect newRectangle = CGRectMake(0, 0, width, height); UIGraphicsBeginImageContext(newSize); [self.image drawInRect:newRectangle]; UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
return resizedImage;
}
@end
Kai Aldag
Courses Plus Student 13,560 Pointsany idea Stone Preston
Kal K
13,332 Points:( How u fixed it? because I'm having this same problem
1 Answer
Ben Jakuben
Treehouse TeacherLet's take it one step at a time. First we need to verify that your data source for the Recipients view controller has data. The Recipients view controller (CameraViewController) has the property friends as the data source for its table view, and the friends property is set in viewWillAppear. Try logging the friends property after it is set in viewWillAppear:
else {
self.friends = objects;
NSLog(@"%@", self.friends);
[self.tableView reloadData];
}
Kai Aldag
Courses Plus Student 13,560 Pointsok Ben Jakuben i found the problem but now the message isn't showing in the inbox view controller.
Ben Jakuben
Treehouse TeacherOkay, would you mind posting a new Forum question with new InboxViewController code to take a look at? :)
Kal K
13,332 Points:( How u fixed it? because I'm having this same problem with the recipients not showing
Ben Jakuben
Treehouse TeacherHi Kalson,
Please start a new thread and paste in details about your code and errors and we can go from there. :)
Stone Preston
42,016 PointsStone Preston
42,016 Pointscan you post the code for your camera view controller?