» 首頁 » 討論區 » iOS程式討論 »ActionSheet範例

ActionSheet範例

發表人: Seachaos
積分: 2432
發表時間: 2012-02-02 18:02:22
ActionSheet是iOS中一種pop up式的表單
如下圖
Image

這是初始化程式碼
[sea:javaCode]
UIActionSheet *actionSheet = [[UIActionSheet alloc ] initWithTitle:@"SelectButton" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Button 0", @"Button 1", nil];
[actionSheet showInView:self.view];
[actionSheet release];
[/sea]
另外他的 Delegate 是用 UIActionSheetDelegate 這個Protocol

[sea:javaCode]
#pragma mark - UIActionSheetDelegate
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex==actionSheet.cancelButtonIndex){
NSLog(@"Cancel");
return;
}
switch (buttonIndex) {
case 1:
NSLog(@"Button 1 pressed");
break;
case 0:
NSLog(@"Button 0 pressed");
break;
}
}
[/sea]