如何在UIActionSheet中添加UIPickerView

Apa*_*che 5 iphone uipickerview uiactionsheet

我有任务输入评级(1 - 5)值,所以我找到了以下代码的日期选择器,任何人都可以帮我改变下面的代码,以便添加UIPickerView选择从1到5的速率

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

UIDatePicker *pickerView = [[UIDatePicker alloc] init];
pickerView.datePickerMode = UIDatePickerModeDate;

[menu addSubview:pickerView];
[menu showInView:self.view];   
[menu sendSubviewToBack:pickerView];     
[menu setBounds:CGRectMake(0,0,320, 500)];

CGRect pickerRect = pickerView.bounds;
pickerRect.origin.y = -100;
pickerView.bounds = pickerRect;

[pickerView release];
[menu release];
Run Code Online (Sandbox Code Playgroud)

该做什么,所以评级的文本字段将自动输入UIPIckerView中的选定值

谢谢

sin*_*h99 13

actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self     cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;


    picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,40, 320, 216)];
    picker.showsSelectionIndicator=YES;
    picker.dataSource = self;
    picker.delegate = self;
    picker.tag=SelectedDropDown;
    [actionSheet addSubview:picker];

UIToolbar *tools=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0,320,40)];
tools.barStyle=UIBarStyleBlackOpaque;
[actionSheet addSubview:tools];
[tools release];


UIBarButtonItem *doneButton=[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(btnActinDoneClicked)];
doneButton.imageInsets=UIEdgeInsetsMake(200, 6, 50, 25);
UIBarButtonItem *flexSpace= [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

NSArray *array = [[NSArray alloc]initWithObjects:flexSpace,doneButton,nil];

[tools setItems:array];
[doneButton release];
[flexSpace release];

//picker title
UILabel *lblPickerTitle=[[UILabel alloc]initWithFrame:CGRectMake(60,8, 200, 25)];
lblPickerTitle.text=@"";
lblPickerTitle.backgroundColor=[UIColor clearColor];
lblPickerTitle.textColor=[UIColor whiteColor];
lblPickerTitle.textAlignment=NSTextAlignmentCenter;
lblPickerTitle.font=[UIFont boldSystemFontOfSize:15];
[tools addSubview:lblPickerTitle];


[actionSheet showFromRect:CGRectMake(0,480, 320,215) inView:self.view animated:YES];
[actionSheet setBounds:CGRectMake(0,0, 320, 411)];
[actionSheet release];
Run Code Online (Sandbox Code Playgroud)


Mat*_*ong 3

首先,我认为您可能会将 UIPickerView 与 UIDatePickerView 混淆。日期选择器是一个特殊的选择器,无法自定义,而 UIPickerView 是专门为自定义而设计的。Marc W 的评论是正确的。我之前回答过这个问题,觉得它提供了比尝试将选择器添加到 UIActionSheet 更好的解决方案。

有很多 UIPickerView 教程。