如何在UIActionSheet中显示自定义视图? [英] How to display custom view in UIActionSheet?

查看:88
本文介绍了如何在UIActionSheet中显示自定义视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIView和一个日期选择器,我想在一个操作表中显示。我使用以下代码:

I have a UIView with a date picker that I'd like to display in an action sheet. I'm using the following code:

-(IBAction) button_click:(id)sender{
//UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"the title" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" otherButtonTitles:@"other", nil];

UIActionSheet *sheet = [[UIActionSheet alloc] init];
ActionSheetController *actionSheet = [[ActionSheetController alloc]  initWithNibName:@"ActionSheetView" bundle:nil];    
[sheet addSubview:actionSheet.view];

[sheet showInView:self.view];
}

我得到的是一个新的视图的顶部从底部,这就是它。如果我评论两个中间行的代码和取消注释顶部,以显示一个常规的操作表,它工作正常。任何想法我可能做错了什么?

What I get is a little bit of the top part of the new view coming up from the bottom and that's it. If I comment the two middle lines of code and uncomment the top part to display a regular action sheet, it works fine. Any ideas what I might be doing wrong?

推荐答案

我发现behavoir发生,因为我没有使用UIActionSheet构造函数正确。应该包括按钮和标题:

I've discovered the behavoir occurs because I haven't used the UIActionSheet constructor properly. The buttons and title should be included:

UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Date Picker" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];

这篇关于如何在UIActionSheet中显示自定义视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆