@interface XXViewController : XXNavigationController <UIAlertViewDelegate> {}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:_ContractCallNum message:nil delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
otherButtonTitles:NSLocalizedString(@"Button 1", nil), NSLocalizedString(@"Button 2", nil), nil];
[alert show];
[alert release];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"alertView is %d", buttonIndex);
switch (buttonIndex) {
case 0:
// Cancle
break;
case 1:
{
// Button 1
}
break;
case 2:
{
// Button 2
}
break;
default:
break;
}
}
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel",nil)
destructiveButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"Button 1",nil),
NSLocalizedString(@"Button 2",nil), nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex)
{
case 0:
{
// Button 1
} break;
case 1:
{
// Button 2
}
break;
default:
break;
}
UIAlertView与UIActionSheet使用示例
本文展示了如何在iOS应用中使用UIAlertView和UIActionSheet创建弹出对话框及操作菜单。通过具体代码实例,详细介绍了如何设置标题、按钮文本,并实现点击事件处理。
1310

被折叠的 条评论
为什么被折叠?



