iPhone开发[四]常用控件之ActionSheet与AlertView

来源:未知 责任编辑:责任编辑 发表时间:2013-11-26 22:12 点击:

关键词:ActionSheet AlertView
1、创建一个Single View Application工程,命名为:ActionSheetDemo,如下图

2、在ViewController.xib上放置一个Button,Title为“删除”
      修改ViewController.h,添加操作:
[cpp] 
<span style="font-family:Microsoft YaHei;font-size:18px;">-(IBAction)delete:(id)sender;</span> 
     将Button“删除”的Touch Up Inside与操作delete关联起来(操作方法上一篇已讲过)
3、修改Controller ViewController,让其实现协议UIActionSheetDelegate:
[cpp] view plaincopy
<span style="font-family:Microsoft YaHei;font-size:18px;">//修改,实现UIActionSheetDelegate协议 
@interface ViewController : UIViewController<UIActionSheetDelegate></span> 

4、修改ViewController.m
     实现操作delete,如下
[cpp] 
<span style="font-family:Microsoft YaHei;font-size:18px;">//执行删除操作 
-(IBAction)delete:(id)sender{ 
    UIActionSheet *actionSheet = [[UIActionSheet alloc] 
                                  initWithTitle:@"确定要删除该服务器?"  
                                  delegate:self //actionSheet的代理,按钮被按下时收到通知,然后回调协议中的相关方法 
                                  cancelButtonTitle:@"取消" 
                                  destructiveButtonTitle:@"确定" 
                                  otherButtonTitles:nil]; 
    //展示actionSheet 
    [actionSheet showInView:self.view]; 
}</span> 
ViewController作为ActionSheet的代理,需要实现协议中定义的方法,有2中实现方法
方法一:实现didDismissWithButtonIndex,在ActionSheet消失后做提示处理
[cpp] 
<span style="font-family:Microsoft YaHei;font-size:18px;">//方法1 
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{ 
    NSLog(@"didDismissWithButtonIndex"); 

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Lexical or Preprocessor Issue 'xxx.h
  • ios学习笔记(二)xcode 4.3.2下实现基本交互
  • ios版本的helloworld
  • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
  • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
  • IOS类似iphone通讯录TableView的完整demo【附源码】
  • UITableView一些方法
  • [iPhone中级]iPhone团购信息客户端的开发 (二)
  • 如何为Iphone应用创建启动界面
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1