Ios 如何解雇行动表中的UIPicker?
我有一个带有5个静态单元格的表视图控制器,其中一个调用UIPicker,如下所示:Ios 如何解雇行动表中的UIPicker?,ios,uipicker,Ios,Uipicker,我有一个带有5个静态单元格的表视图控制器,其中一个调用UIPicker,如下所示: #pragma mark PickerView DataSource - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInte
#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会出现,但当我单击“完成”按钮时,现在如何取消它?此外,城市记录为null,我不知道为什么,因为我用这些城市初始化了选取器,它们在出现时确实出现在选取器中。将对UIActionSheet的引用存储在属性或实例变量中
@property (nonatomic) UIActionSheet *actionSheet;
创建操作表时,请使用
self.actionSheet
而不是
UIActionSheet *aac
然后打电话
[self.actionSheeet dismissWithClickedButtonIndex:0 animated:YES];
让它全球化这是我的第一本能,但后来我发现这一点,并试图让它发挥作用。但是我无法让OK按钮显示:
http://stackoverflow.com/questions/7464302/obj-c-showing-a-uipickerview-in-an-uiactionsheet-but-need-to-save-to-nsuserdef
我不确定问题出在哪里-你想显示什么“确定”按钮?我链接到的那篇文章中的那个按钮,是他们创建的actionsheet的其他按钮。
UIActionSheet *aac;