如何在UIActionSheet中显示自定义视图?

发布于 2024-08-28 14:09:59 字数 649 浏览 5 评论 0原文

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

-(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];
}

我得到的是从底部出现的新视图的顶部部分,仅此而已。如果我注释中间的两行代码并取消注释顶部部分以显示常规操作表,则它可以正常工作。有什么想法我可能做错了什么吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鹤仙姿 2024-09-04 14:10:02

我不相信您可以在 UIActionSheet 中指定自定义视图。我的理解是你只能显示一个标题和1个或多个按钮。下面是Apple文档中对UIActionSheet的描述:

使用 UIActionSheet 类向用户提供一组如何继续执行给定任务的替代方案。您还可以使用操作表来提示用户确认潜在危险的操作。操作表包含一个可选标题和一个或多个按钮,每个按钮对应于要执行的一项操作。

UIActionSheet 类参考

I do not believe you can specify Custom Views in a UIActionSheet. My understanding is that you can only display a title and 1 or more buttons. Below is the description of UIActionSheet in the Apple documentation:

Use the UIActionSheet class to present the user with a set of alternatives for how to proceed with a given task. You can also use action sheets to prompt the user to confirm a potentially dangerous action. The action sheet contains an optional title and one or more buttons, each of which corresponds to an action to take.

UIActionSheet Class Reference

强辩 2024-09-04 14:10:02

我发现发生这种行为是因为我没有正确使用 UIActionSheet 构造函数。应包含按钮和标题:

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

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];
月依秋水 2024-09-04 14:10:02

您可能想查看我制作的 UIActionSheet 替代方案,它可以让您显示自定义内容视图,而无需任何肮脏的黑客: https:// github.com/JonasGessner/JGActionSheet 与 UIActionSheet 相比,它还有一些其他优点!

You might want to check out an UIActionSheet alternative I made which lets you display custom content views without any dirty hacks: https://github.com/JonasGessner/JGActionSheet It has some other advantages over UIActionSheet as well!

乙白 2024-09-04 14:10:01

使用 UIActionSheetDelegate,之后您可以使用此委托将图像添加到警报表的按钮

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet{

   UIImageView *sample = [[UIImageView alloc] initWithImage:[UIImage       
   imageNamed:@"Someimage.png"]];
   [actionSheet addSubView:sample];

}

use UIActionSheetDelegate and after that you can with this delegate add for example a image to button of alertsheet

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet{

   UIImageView *sample = [[UIImageView alloc] initWithImage:[UIImage       
   imageNamed:@"Someimage.png"]];
   [actionSheet addSubView:sample];

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文