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 Capturing Photo and Video Using UIImagePickerController Saving the Media

I have completed everything that was said. I go to run it. tap photos. then in the console it says I the app crashed.

I dont know what happened? "Presenting view controllers on detached view controllers is discouraged" That is part of the things the console says. Please help me!!!

https://www.dropbox.com/s/fr3vznk5c3demyd/self%20Destruct.zip?dl=0

Naomi Freeman
Naomi Freeman
Treehouse Guest Teacher

Could you please share your code with us too? Thanks :)

its all in the dropbox file.

Naomi Freeman
Naomi Freeman
Treehouse Guest Teacher

Thanks! Sorry. On smaller screen at the moment and just the images came up initially :)

here is a link (https://www.dropbox.com/s/fr3vznk5c3demyd/self%20Destruct.zip?dl=0) to the zipfile. Sorry if the other one was an inconvenience.

I hope you can find the answer. Thanks again!

1 Answer

Aaron Malone
Aaron Malone
15,762 Points

Does it possibly say something about *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] after that warning?

Looking at your code, I see

static NSString *CellIdentifier=@"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

in your cameraTableViewController.m.

That CellIdentifier is what the program uses to know which UITableViewCell instances it can use and reuse when scrolling through your table view. Before you can use it, though, it has to be registered with the application somehow. That can be done in code, but it's simpler to add that in your storyboard.

In the storyboard, select the correct scene (I think it's "recipients scene" in your storyboard), and in the outline, click on "Table View Cell", then go to the attributes inspector on the right side of the XCode window. Near the top of the attributes inspector is a box labeled "Identifier"; this is where you can put in the reuse identifier; in this case it would just be "Cell", though you'll probably want to use different identifiers for the different table views in your app.

I tried your suggestion. It did not work.

I don't why but When I put the code below in the viewWillApear method it does act up. But when It is in the viewDidLoad it works fine. But putting it in viewDidLoad is not an option because when I attempt to take a second picture I can't.

PFQuery *query = [self.friendsRelation query];

    [query orderByAscending:@"username"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"error %@ %@" , error, [error userInfo]);
        }
        else{
            self.friends = objects;
            [self.tableView  reloadData];


        }

    }];


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