iOS 底部对话框UIActionSheet

UIActionSheet提供了一个菜单式的界面,为用户提供操做命令选项,界面是从屏幕底部向上弹出。

下面提供了使用UIActionSheet的样例代码:

定义UIActionSheet对象

在类中申明UIActionSheet对象,若是须要处理选择UIActionSheet项后的消息,则须要使用UIActionSheetDelegate。 .net

@interface  MyClassController : UIViewController <UIActionSheetDelegate>
{
  UIActionSheet *sheet;
}
@end
建立和显示UIActionSheet

在建立UIActionSheet对象时,指定接收UIActionSheetDelegate代理对象。

sheet = [[UIActionSheet alloc] initWithTitle:@"Select Belgian Beer Style"
                                      delegate:self
                             cancelButtonTitle:@"Cancel"
                       destructiveButtonTitle:nil
                            otherButtonTitles:@"Dubble", @"Lambic", @"Quadrupel", @"Strong Dark Ale", @"Tripel", nil];
 
  // Show the sheet
  [sheet showInView:self.view];
  [sheet release];


判断哪个选项被选中,在MyClassController中实现下面方法,在此方法中实现须要处理的逻辑。

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
  NSLog(@"Button %d", buttonIndex);
}
相关文章
相关标签/搜索