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 trialAndrey Balyasnikov
6,313 Points[extra credit] Capturing Photo and Video Using UIImagePickerController (Ribbit)
Hi guys!
I've got the problem with extra credit: "Right now, we are not displaying anything to the user if a message is successfully sent. Instead, add a brief popup message using a third party library like MBProgressHUD. Get creative with the display, but a good starting point would be a simple automatic message at the bottom of the screen."
problem: I don't know how to show message in the inbox screen after the message is sent. It appears only in the recipients screen.
here is my code: https://github.com/abalyasnikov/Ribbit/tree/master/Ribbit
I guess that it only initialises in cameraViewController, but not in inboxViewController. How to pass and capture this message in the inbox screen with showHUDAddedTo: method?
4 Answers
Stone Preston
42,016 Pointshmm with it being added to the tabBar it seems like it should display regardless of the tab that is selected.
another option is to use a notification. in your camera view controller you will have to post the notification whenever the message is sent:
[[NSNotificationCenter defaultCenter] postNotificationName:@"messageSent" object:nil];
then subscribe to that notification in your inbox view controller:
//used to track when a user sends a message
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(displayMessageSentMessage)
name:@"messageSent"
object:nil];
add a new displayMessageSentMessage method (the selector that is called when the notification is posted) that does all the progressHUB stuff and it should work
- (void)displayMessageSent {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.tabBarController.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = @"Message sent";
hud.margin = 10.f;
hud.yOffset = 150.f;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:3];
}
also in your view controllers dealloc method you would need to unsubscribe from the notification:
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"messageSent" object:nil];
orlando arzola
11,868 PointsHello,
I am using this method to call the message. However, the message is shown in the camera section. I would like to show it in the Inbox View after the message is sent
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
// Configure for text only and offset down
hud.mode = MBProgressHUDModeText;
hud.labelText = @"Message Sent";
hud.margin = 10.f;
hud.yOffset = 100.f;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:3];
I know I have to change this "self.navigationController.view" to point at the inbox view but I have no idea how to do so.
Thanks
Stone Preston
42,016 Pointssee my above post on how to display the hud message in your inbox instead of camera using notifications. changing self.navigationController.view wont work since the inbox navigation controller and camera nav controller are 2 separate controllers.
orlando arzola
11,868 PointsOh thanks. Actually, I used this method "self.tabBarController.view" and the message was shown on the inbox. Any suggestion why that happened?
Stone Preston
42,016 Pointscan you post the full line of code you used?
orlando arzola
11,868 Points-
(IBAction)send:(id)sender { if (self.image == nil && [self.videoFilePath 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]; [self presentViewController:self.imagePicker animated:NO completion:nil]; } else { [self uploadMessage]; [self.tabBarController setSelectedIndex:0];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.tabBarController.view animated:YES]; // Configure for text only and offset down hud.mode = MBProgressHUDModeText; hud.labelText = @"Message Sent"; hud.margin = 10.f; hud.yOffset = 100.f; hud.removeFromSuperViewOnHide = YES; [hud hide:YES afterDelay:2];
} }
I got it. Because the tabBarController was set to 0 (inbox view controller) the message was supposed to be shown there when I selected self.tabBarController.view
Stone Preston
42,016 Pointsyes thats correct
Andrey Balyasnikov
6,313 PointsAndrey Balyasnikov
6,313 PointsStone, thanks a lot! it perfectly works, but I'm not sure about dealloc method.
Is that correct?
Stone Preston
42,016 PointsStone Preston
42,016 PointsAndrey Balyasnikov yes that looks correct.