UIActionSheet是IOS系统提供的选择提示项,效果如下图:
使用很方便,每一项点击都可以在代理中监听到,不用考虑适配问题,代码如下:
UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"拍照",@"从手机相册选择", nil];
[as showInView:self.navigationController.view];
使用注意点:
1.initWithTitle为初始化方法,参数title表示标题,可以设置成nil不显示
2.cancelButtonTitle为取消按钮,点击后UIActionSheet消失
3.可以更具实际情况自己增加按钮。使用otherButtonTitle是设置
4.如果想使用代理,控制器继承UIActionSheetDelegate,一般实现clickedButtonAtIndex方法即可
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
}else if (buttonIndex == 1) {
}
}
buttonIndex代表点击UIActionSheet的哪一项,然后根据判断写逻辑即可。
5.在某些特殊情况下,UIActionSheet的otherButtonTitles不是固定的,需要根据实际情况变化;我们可以使用如下方法添加:
UIActionSheet *mySheet = [[UIActionSheet alloc] initWithTitle:@"请选择"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:nil];
NSMutableArray *jlInfos=[FMUserInfo sharedInstance].jlInfos;
NSString *rsName=@"";
for(FMJlInfo *info in jlInfos){
if(![Tools isBlankString:info.resumeName]){
rsName=info.resumeName;
}
<span style="color:#ff6666;">[mySheet addButtonWithTitle:rsName];</span>
}
[mySheet showInView:self.navigationController.view];
[mySheet addButtonWithTitle:rsName];即是代码添加方法