嗨誰能幫我這個,我一直都在對這個問題以前的問題很多,他們似乎有點複雜。我想設置一個選擇器,通過觸摸一個名爲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中點擊(位置字段)彈出。
謝謝
非常感謝您的幫助,它在設置這些方法後不再崩潰。無論如何,我想說如果說正在編輯某個文本字段,然後顯示某個選擇器? (我有兩個每個)我猜我可以用標籤做到這一點?你是否可以檢查我在那裏的號碼,只有一半的工具欄顯示,當我運行它時沒有選擇器在屏幕上。 – dev6546
您的視圖控制器是否具有對任一文本字段的引用?然後做'if(textField == self.whateverField){//顯示錶單,返回NO} else {//做其他任何事情}' –
非常感謝你,然後我會使用標籤作爲拾取器。你如何看待選取框和標籤欄的矩形?我必須弄錯數字,因爲它只在屏幕底部顯示一半標籤欄。 – dev6546