UIActionSheet是在iOS弹出的选择按钮项,可以添加多项,并为每项添加点击事件.

使用

1.需要实现UIActionSheetDelegate  协议

@interface NJWisdomCardDetailViewController ()<UIActionSheetDelegate>

@end

2.弹出选择按钮框

- (void)showSheet{
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"title,nil时不显示"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"确定"
otherButtonTitles:@"第一项", @"第二项",nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self.view];
}

参数解释:

  • actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;//设置样式
  • cancelButtonTitle和destructiveButtonTitle 是系统带的两个按钮。
  • otherButtonTitles是自己定义的项,注意,最后一个参数要是nil。
  • [actionSheet showInView:self.view]; 这行语句的意思是在当前view显示Action sheet。

设置样式,操作表单也支持三种风格:

  • UIActionSheetStyleDefault              //默认风格:灰色背景上显示白色文字
  • UIActionSheetStyleBlackTranslucent     //透明黑色背景,白色文字
  • UIActionSheetStyleBlackOpaque          //纯黑背景,白色文字

3.监听项的点击事件。实现协议里的有相应的方法

(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == ) {
[self showAlert:@"确定"];
}else if (buttonIndex == ) {
[self showAlert:@"第一项"];
}else if(buttonIndex == ) {
[self showAlert:@"第二项"];
}else if(buttonIndex == ) {
[self showAlert:@"取消"];
}
}
- (void)actionSheetCancel:(UIActionSheet *)actionSheet{ }
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{ }
-(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{ }

注意事项

在开发过程中,发现有时候UIActionSheet的最后一项点击失效,点最后一项的上半区域时有效,这是在特定情况下才会发生,这个场景就是试用了UITabBar的时候才有。解决办法:

在showView时这样使用,[actionSheet showInView:[UIApplication sharedApplication].keyWindow];或者[sheet showInView:[AppDelegate sharedDelegate].tabBarController.view];这样就不会发生遮挡现象了。

最新文章

  1. Singleton(单例模式)的一种实现 -- 基于【惰性】适用于【大对象】的一种生产实践
  2. webdriverAPI-Java
  3. 写PHP代码你搞过单元测试吗
  4. linux下使用yum安装mysql详解
  5. Sql Server之旅——第一站 那些给我们带来福利的系统视图
  6. (六)责任链模式-C++实现
  7. map与vector---Email Aliases
  8. K Best(最大化平均数)_二分搜索
  9. iOS 2D绘图详解(Quartz 2D)之阴影和渐变(Shadow,Gradient)
  10. 教你利用iframe在网页中显示天气
  11. wpf 绑定失效的原因及解决方案
  12. HDU2669 第六周练习I题(扩展欧几里算法)
  13. hdu 1301
  14. Java用ZIP格式压缩和解压缩文件
  15. Log4net配置与使用简要说明
  16. 无代理处理post非简单请求跨域问题
  17. FutureTask并发详解,通俗易懂
  18. WPF Path总结(一)
  19. [PHP] 数据结构-线性表的顺序存储结构PHP实现
  20. 【评分】Alpha阶段

热门文章

  1. html2canvas - 实现网页截图(+下载截图) 功能
  2. jQuery的回调管理机制
  3. jQuery(&quot;dom&quot;).get()的源码分析
  4. sencha touch 自定义cardpanel控件 模仿改进NavigationView 灵活添加按钮组,导航栏,自由隐藏返回按钮(废弃 仅参考)
  5. JVM学习--开启应用的gc日志功能
  6. 添加Net4CollectionTypeFactory的原因
  7. SSL/TLS 握手优化详解
  8. 使用VS Code编译运行C/C++程序
  9. Assign the task---hdu3974(线段树优化+dfs)
  10. ChinaTest测试感悟