开发者

How to create an iPhone Album's "email photo, MMS, Assign To Contact.." like sliding view?

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.


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
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜