gpt4 book ai didi

ios - 如何关闭操作表中显示的 UIPicker?

转载 作者:行者123 更新时间:2023-11-29 03:44:43 27 4
gpt4 key购买 nike

我有一个带有 5 个静态单元格的 TableView Controller ,其中一个像这样调用 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 已呈现,但当我单击“完成”按钮时,但现在如何将其关闭?另外,该城市正在记录空,我不确定为什么,因为我用这些城市初始化了选择器,并且一旦呈现,它们就会出现在选择器中。

最佳答案

将对 UIActionSheet 的引用存储在属性或实例变量中

@property (nonatomic) UIActionSheet *actionSheet;

当您创建操作表时使用

self.actionSheet

而不是

UIActionSheet *aac

然后调用

[self.actionSheeet dismissWithClickedButtonIndex:0 animated:YES];

关于ios - 如何关闭操作表中显示的 UIPicker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17893927/

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