views:

218

answers:

1

I learned how to create a view controller and make the view slide in from bottom. But the one in iphone album looks different. It darkens the rest of the visible portion of the screen when the view slides in. How do I create a similar one? I want to add buttons like "save, cancel, email" etc into the sliding view.

+2  A: 

This actually isn't a typical "sliding" (or modal) view, but a UIActionSheet. Basically, the idea is that you initialize the view (usually in your view controller) with

UIActionSheet *sheet = 
    [[[UIActionSheet alloc] initWithTitle:@"My sheet"
                                 delegate:self
                        cancelButtonTitle:@"Cancel"
                   destructiveButtonTitle:nil
                        otherButtonTitles:@"Email", @"MMS", nil] autorelease];

Then present it using

[sheet showInView:[self view]];

Once it's onscreen, the delegate (self, or your view controller, in this example) will receive the UIActionSheetDelegate message actionSheet:clickedButtonAtIndex: (as well as some others; see the documentation for more), so you'll want to add <UIActionSheetDelegate> to your interface declaration for the delegate and implement that method, like

- (void)actionSheet:(UIActionSheet *)actionSheet 
    clickedButtonAtIndex:(NSInteger)buttonIndex {
    switch(buttonIndex) {
        // Do things based on which button was pushed
    }
}
Tim
Thanks a lot Tim! initially the cancel button wasn't working then i found that it is because the button was above the tabs. So I change the presenting code to...[sheet showInView:self.parentViewController.view];and thats working :)
Pankaj
don't forget to mark that answer as the "correct" answer by checking it.
Jean-Denis Muys
@pankajgoswami: note that UIActionSheet also has a method `showFromTabBar:` that lets you present it above a UITabBar (since it sounds like that's what you're doing)
Tim