0
我有一個5個靜態單元格的表視圖控制器和一個叫這樣的UIPicker:如何解除操作表中顯示的UIPicker?
#pragma mark PickerView DataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [self.cityNames count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [self.cityNames objectAtIndex:row];
}
#pragma mark PickerView Delegate
-(void)presentNewPicker{
UIActionSheet *aac = [[UIActionSheet alloc] initWithTitle:@"For which city?"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
self.pickrView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
self.pickrView.showsSelectionIndicator = YES;
self.pickrView.dataSource = self;
self.pickrView.delegate = self;
self.cityNames = [[NSArray alloc] initWithObjects: @"Akron", @"Indie", @"Springfield", @"Loria", @"Merida", nil];
UIToolbar *pickerDateToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerDateToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerDateToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClick)];
[barItems addObject:doneBtn];
[pickerDateToolbar setItems:barItems animated:YES];
[aac addSubview:pickerDateToolbar];
[aac addSubview:self.pickrView];
[aac showInView:self.view];
[aac setBounds:CGRectMake(0,0,320, 464)];
}
-(void) dismissActionSheet:(id)sender {
NSLog(@"dismissActionSheet");
UIActionSheet *actionSheet = (UIActionSheet *) ??? how do i get action sheet? :-);
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
self.myCity.text = [self.cityNames objectAtIndex:row];
NSLog(@"city %@", self.myCity.text);
}
的UIPicker呈現但是當我點擊完成按鈕,但我怎麼現在解僱呢?此外,這座城市的日誌記錄爲空,我不知道爲什麼,因爲我啓動了與這些城市的選擇器,並且一旦它們呈現,它們就會出現在選取器中。
嗯,這是我的第一反應,但後來我發現這對SO,並試圖使其工作。但我不能讓OK按鈕顯示出來:'http://stackoverflow.com/questions/7464302/obj-c-showing-a-uipickerview-in-an-uiactionsheet-but-need-to-save-to- nsuserdef' – marciokoko
我不確定是什麼問題 - 您想要顯示哪個確定按鈕? – Kevin
我鏈接到的那篇文章中的那個,它的動作表的其他按鈕他們創建的。 – marciokoko