How to display custom view in UIActionSheet?

I have a UIView with a date picker that I would like to display in the action sheet. I am 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 the slightly upper part of the new view coming from below and this. If I comment out the two middle lines of code and uncomment the top to display a normal action sheet, it works fine. Any ideas what I can do wrong?

+3
source share
4 answers

I found that the behavior is because I did not use the UIActionSheet constructor correctly. Buttons and title should be included:

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

UIActionSheetDelegate, , , alertheet

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

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

}
+1

, UIActionSheet. , 1 . UIActionSheet Apple:

UIActionSheet, . , . , .

UIActionSheet

0

You might want to check out the UIActionSheet alternative that I created that allows you to display custom kinds of content without any dirty hacks: https://github.com/JonasGessner/JGActionSheet . Some other advantages over UIActionSheet!

0
source

Source: https://habr.com/ru/post/1740626/


All Articles