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

Help with Self Destructing Message Project

Hi All,

I've finished the Self Destructing App, however what I've done is split the sending process into two view controllers - one for ImagePicker / Adding a Subject & Message, and another for displaying recipients and sending. It's all working fine, and I can display the text fine in the ImageViewController - however I have a similar bug to the one Ben purposefully created in the Project where after sending a message, returning to the camera tab takes you straight to the Recipient selection (Which isn't the root). The way I'm going from the send button to the inbox is the same as the tutorial:

<p>[self.tabBarController setSelectedIndex:0];</p>

I've also tried doing a Poptoroot, but naturally that only gets me half the way back. I've got a feeling it's something I'm misunderstanding about the View Controller life cycle, but I can't see what I could place into "ViewDidLoad" etc to solve this. I've really done my best to solve this problem, and will continue to attempt to solve it - but I could really do with some treehouse help if possible?

3 Answers

why not try using

- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated

however why isnt the imagePicker/subject view controller the root in the navigation stack? shouldnt it be?

Hi Stone,

I'll give it a go! The ImagePicker / Subject ViewController is definitely set as the NavController root which is why I'm rather confused...

I'll report back soon, thank you for the reply!

alright. Can you post the line of code you were using to pop to the root view controller that wasnt working?

This is the code I have that sent the message and returned to Inbox:

'''

- (IBAction)send:(id)sender {
    if (self.messageImage == nil && [self.vidFilePath length] == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Try again!" message:@"Please capture or select a photo or video to share!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alertView show];
    }
    else {
        [self uploadMessage];
        [self.tabBarController setSelectedIndex:0];

    }
}

'''

When I implemented a poptoroot, it did display the Picker / Subject Controller fine - just reading up on implmenting the NSArray PopToView so will be back with you soon!

Ok I've now solved this by approaching it slightly differently...Instead of making the Message entry view the first view controller, I made it the second and added a programmatic segue that only triggers if an image is present. Once the text has been entered it then segue's back to the first controller presenting the recipients. Probably not exactly what I should be doing, but it seems to work absolutely fine!