【发布时间】:2016-06-09 19:44:27
【问题描述】:
我有 uitextfield 并添加了选择器视图作为输入视图。
一切都很完美。我的问题是,一旦我单击 uitextfield 选择器视图,就会出现值。但我从数据库中获取了一些数据,这些数据将根据选择的选择器值更新到另一个文本框。
我从数据库获取数据时有 5-6 秒的时间间隔。但是在调用返回数据之前,可以看到带有预加载值的选取器视图。
我只是想添加一种延迟,直到我从 DB 选择器值中获取数据不可见... 注意:我已经使用隐藏。不能正常工作。
UIPickerView *vwlistPicker = [[UIPickerView alloc] init];
[vwlistPicker sizeToFit];
vwlistPicker.delegate = self;
vwlistPicker.dataSource = self;
vwlistPicker.showsSelectionIndicator = YES;
UITextField *txtPayType = [[UITextField alloc] initWithFrame:CGRectMake(0, 65, 250, 30)];
txtPayType.layer.borderWidth = 0.5;
txtPayType.layer.masksToBounds = true;
txtPayType.layer.cornerRadius = 5;
txtPayType.layer.borderColor = [[UIColor blackColor] CGColor];
txtPayType.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
txtPayType.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
txtPayType.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
txtPayType.tag = 1;
[txtPayType setDelegate:self];
txtPayType.text = [tempDic valueForKey:@"PayType"];
[txtPayType setFont:[UIFont fontWithName:@"Avenir-Medium" size:15.0]];
[txtPayType setTextColor:[UIColor colorWithRed:19.0/255.0 green:62.0/255.0 blue:137.0/255.0 alpha:1]];
[txtPayType setReturnKeyType:UIReturnKeyDone];
txtPayType.inputView = vwlistPicker;
UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
keyboardDoneButtonView.barStyle = UIBarStyleDefault;
keyboardDoneButtonView.translucent = NO;
keyboardDoneButtonView.barTintColor = [UIColor colorWithRed:10.0/255.0 green:23.0/255.0 blue:75.0/255.0 alpha:0];
[keyboardDoneButtonView sizeToFit];
UIBarButtonItem* doneButton = [[[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStylePlain target:self
action:@selector(itemPickerDoneClicked:)] autorelease];
UIBarButtonItem* cancelButton = [[[UIBarButtonItem alloc] initWithTitle:@"Cancel"
style:UIBarButtonItemStylePlain target:self
action:@selector(itemPickerCancelClicked:)] autorelease];
[keyboardDoneButtonView setItems:[NSArray arrayWithObjects:doneButton,cancelButton, nil]];
txtPayType.inputAccessoryView = keyboardDoneButtonView;
[self.view addSubview:txtPayType];
//Textfield delegate
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField.tag == 1)
{
[vwlistPicker setHidden:TRUE];
double delayInSeconds = 5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[vwlistPicker reloadInputViews];
textField.inputView = vwlistPicker;
[vwlistPicker reloadAllComponents];
[vwlistPicker setHidden:FALSE];
});
// Call to DB and get Data //
}
我添加了延迟/隐藏(键盘以及pickerview),但仍然出现键盘。并在延迟后出现选择器视图选项。
我不想显示任何东西,一旦我得到数据选择器视图就会出现。
【问题讨论】:
-
与其延迟为什么不显示一个微调器,然后用正确的值显示选择器?
-
不,我需要数据,因为...取决于选择器视图选项值,数据在第二个文本字段上进行修改。就像我已经有选择器视图值一样,但是取决于用户选择,我需要将 DB 中的其他值更改为不固定的值。所以碰巧我的选择器视图出现在我调用 db 之前的第一个,我得到数据。
-
如何获取数据?
-
我只是想延迟选择器视图的出现.....数据获取是iOS的正常方式......这不会影响......我已经提到了我想延迟的原因...... ..
标签: ios objective-c uipickerview