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);
}
相關文章
相關標籤/搜索