gpt4 book ai didi

objective-c - 点击按钮时显示 UIPickerView

转载 作者:行者123 更新时间:2023-11-29 04:50:59 24 4
gpt4 key购买 nike

标题完全解释了我此时尝试管理的内容。简而言之,我喜欢 here 中的例子.只有一个问题,在这个例子中使用的是 UIDatePicker 而不是普通的 UIPickerView。我的问题是我无法使用 NSMutableArray 中的数据输入 UIPickerView 。我试图以常见的方式完成它,使用三种基本方法来使“鼓”运行。

现在在 viewDidLoad 中:self.uiPickerViewData=[[NSMutableArray alloc]initWithObjects:@"One",@"Two", nil];

//when tapping on Set Quality button
- (IBAction)setQuality:(id)sender
{

actionSheet=[[UIActionSheet alloc]initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleDefault];

CGRect pickerFrame=CGRectMake(0, 44, 0, 0);
qualityPicker=[[UIPickerView alloc]initWithFrame:pickerFrame];
qualityPicker.delegate=self;
[actionSheet addSubview:qualityPicker];

[qualityPicker release];

UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, actionSheet.bounds.size.width, 44)];
[toolBar setBarStyle:UIBarStyleDefault];
[toolBar sizeToFit];

UIBarButtonItem *spacer=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *setButton=[[UIBarButtonItem alloc]initWithTitle:@"Set" style:UIBarButtonSystemItemCancel target:self action:@selector(setQualityIntoDB)];
UIBarButtonItem *cancelButton=[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];

[toolBar setItems:[NSArray arrayWithObjects:spacer,setButton,cancelButton, nil]animated:NO];
[spacer release];
[setButton release];
[cancelButton release];

[actionSheet addSubview:toolBar];
[toolBar release];

[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}

还有一些要点并没有给我带来预期的结果。

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}

- (NSInteger)numberOfRowsInComponent:(NSInteger)component
{
return [uiPickerViewData count];
}

-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [uiPickerViewData objectAtIndex:row];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// Will be properly implemented later

DBAccess *access=[[DBAccess alloc]init];
[access closeDataBase];
[access release];
}

我的 UIPickerView 为空。问题出在哪里?

最佳答案

在 View 下创建一个不可见的选择器和工具栏后,在此处使用此方法(坐标 = (0,640)):

- (void)showPicker{

[UIView beginAnimations:@"picker" context:nil];
[UIView setAnimationDuration:0.5];

picker.transform = CGAffineTransformMakeTranslation(0,- pickerHeight);
pickerToolbar.transform = CGAffineTransformMakeTranslation(0, - pickerHeight - toolbarHeight);

[UIView commitAnimations]; }

-(void)hidePicker{
[UIView beginAnimations:@"picker" context:nil];
[UIView setAnimationDuration:0.5];

picker.transform = CGAffineTransformIdentity;
pickerToolbar.transform = CGAffineTransformIdentity;

[UIView commitAnimations]; }

然后将 showPicker 添加为按钮的操作,将 hidePicker 添加为您想要的其他内容的操作。

关于objective-c - 点击按钮时显示 UIPickerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8852088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com