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 Diary App Using Core Data Custom Detail View Controller Implementing a UIImagePickerController

Jonathan Fernandez
Jonathan Fernandez
8,325 Points

Reverse Camera Button Bug in Diary App?

Just wanted to point out that I had found a bug with the Diary app when I had tested out the camera on my iPhone. The buttons were reversed in which when I would tap the camera button, the photo album would be brought up and when I tapped photo album the camera would be brought up instead.

Found below is the code which I believe to have caused this reversed bug. You can see it defined in the video at around 3:00 min.

Code:

<p>
// EntryViewController.m
// ...
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex != actionSheet.cancelButtonIndex) {
        if (buttonIndex != actionSheet.firstOtherButtonIndex) {
             [self promptForCamera]; // Called after photo album was pressed.
        } else {
             [self promptForPhotoRoll]; // Called after camera button was pressed.
        }
    }
}
// ...
</p>

4 Answers

Jonathan Fernandez
Jonathan Fernandez
8,325 Points

I was able to get past this bug by simply reversing the code shown here.

<p>
// EntryViewController.m
// ...
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex != actionSheet.cancelButtonIndex) {
        if (buttonIndex != actionSheet.firstOtherButtonIndex) {
             [self promptForPhotoRoll]; // Switched
        } else {
             [self promptForCamera]; // Switched
        }
    }
}
// ...
</p>

Hope this helps anyone in case they have come across this bug like me. : )

Kieran Robinson
Kieran Robinson
9,411 Points

Hi Jonathan Fernandez, i didn't realise this was a bug within the video i thought id done it wrong!! let Ash Furrow know so he can link this fix in the teachers notes of the video!

Ash Furrow
Ash Furrow
Treehouse Guest Teacher

Hmm, interesting. My apologies about that. Amit Bijlani : is that something we can amend?

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

I've added a link to this post in the teachers notes below the video. Thanks for bringing this to our attention!

Jonathan Fernandez
Jonathan Fernandez
8,325 Points

Hi Kieran Robinson it seems that they have already found the post and have added the note to the video. : )

Just wanted to also thank you guys for having such awesome classes and I'm really enjoying them! ^^

Martin Mรคgi
Martin Mรคgi
8,295 Points

It can also be fixed by simply removing the ! sign in the second if sentence and adding another = sign (changing the sentence from not equal to equal).

Before:

if (buttonIndex != actionSheet.firstOtherButtonIndex)

After:

if (buttonIndex == actionSheet.firstOtherButtonIndex)

how about if have bug like this ? https://www.dropbox.com/s/kjggelxfhiov6ns/Bug%20on%20UI.PNG?dl=0

that a picture of output i made . how to fix that ? thx