嗨,任何人都可以帮我解决这个问题,我一直在研究关于这个主题的很多以前的问题,它们似乎有点复杂。我想设置一个选择器,该选择器在触摸具有称为 locationField 的 IBOutlet 的文本字段时进行动画处理。
我不想在我的故事板中添加选择器或工具栏和按钮,我宁愿以编程方式进行。
到目前为止,我有:
- (void)viewDidLoad
{
//populate picker arrays
locationPickerArray = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
actionSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet showInView:self.view];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,480,32)];
[pickerToolbar sizeToFit];
pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonSystemItemCancel target:self action:@selector(cancel_clicked:)];
[barItems addObject:cancelBtn];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(done_clicked:)];
[barItems addObject:doneBtn];
[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];
UIPickerView *picker = [[UIPickerView alloc] init];
picker.frame = CGRectMake(0, 44, 320, 216);
picker.delegate = self;
picker.dataSource = self;
picker.showsSelectionIndicator = YES;
[actionSheet addSubview:picker];
}
-(void)done_clicked:(id)sender
{
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
-(void)cancel_clicked:(id)sender
{
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
我对此有几个问题,它崩溃了:
*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[DetailsScreenViewController numberOfComponentsInPickerView:]:无法识别的选择器发送到实例 0xb505be0”
这是什么意思?
我的最后一个问题是,当单击我之前创建的 iboutlet(位置字段)时,如何填充此选择器并将其分配给弹出窗口。
谢谢