IOS提示控件UIActionSheet,UIAlertView

实际显示效果图(UIActionSheet)

211316_2o0N_927576.png

实现代码:

@interface ContactsTableViewController () <UIActionSheetDelegate> //此处要添加代理
- (IBAction)logout:(id)sender;

@end
/************************************************************************/

- (IBAction)logout:(id)sender {
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"你确定要退出?" 
                                                    delegate:self 
                                                    cancelButtonTitle:@"取消" 
                                                    destructiveButtonTitle:@"确定" 
                                                    otherButtonTitles:nil, nil];
    [sheet showInView:self.view];
}

#pragma mark - actionsheet的代理方法
//图上注销(退出到首页)的具体实现
- (void)actionSheet:(UIActionSheet *)actionSheet 
                                     clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex != 0 ) return;
 
    [self.navigationController popViewControllerAnimated:YES];
}

-------------------------------------------------------------------------------------------------------------------------

定义两个控件事件方法

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
- (IBAction)showActionSheet:(id)sender;
- (IBAction)showAlertView:(id)sender;
@end


实现事件

- (IBAction)showActionSheet:(id)sender
{
    UIActionSheet *showSheet = [[UIActionSheet alloc] initWithTitle:@"提示信息" 
        delegate:self cancelButtonTitle:@"取消" 
        destructiveButtonTitle:@"确认" 
        otherButtonTitles:nil];
    [showSheet showInView:self.view];
    [showSheet release];
}

- (IBAction)showAlertView:(id)sender
{
    UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:@"提示信息" 
                                message:@"啊啊" 
                                delegate:self 
                                cancelButtonTitle:@"取消" 
                                otherButtonTitles: nil];
    [alterView show];
    [alterView release];
}


UIActionSheet委托代码 ,当点击确认后,弹出UIAlertView窗口提示信息

- (void) actionSheet: (UIActionSheet *) actionSheet
didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSString *msg = nil;
    if (buttonIndex != [actionSheet cancelButtonIndex]) {
        msg = [NSString stringWithString:@"你选择了确认"];
    }else {
        msg = [NSString stringWithString:@"你选择了取消"];
    
    }
    UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示信息" 
                                                message:msg 
                                                delegate:self 
                                                cancelButtonTitle:@"取消" 
                                                otherButtonTitles: nil];
    [alter show];
    [alter release];
    [msg release];
    
}


转载于:https://my.oschina.net/227/blog/384513

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值