UITextView issue with ActionSheetStringPicker Picker view

半城伤御伤魂 提交于 2019-12-02 01:13:54
Mallikarjun Hanagandi

I think the following IBAction code:

- (IBAction)staffClicked:(id)sender {
    [self.view endEditing:YES];
    if (!_staffArray||!_staffArray.count) {
        _assignTextField.text=NSLocalizedString(@"Not Available",nil);
        staff_id=0;
    }else{

        [ActionSheetStringPicker showPickerWithTitle:NSLocalizedString(@"Select Assignee",nil) rows:_staffArray initialSelection:0 target:self successAction:@selector(staffWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:sender];
    }
}

... and the following methods:

- (void)staffWasSelected:(NSNumber *)selectedIndex element:(id)element
{
    staff_id=(staff_idArray)[(NSUInteger) [selectedIndex intValue]];
    self.assignTextField.text = (_staffArray)[(NSUInteger) [selectedIndex intValue]];
}


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    return NO;
}

... will solve your problem for you.

It's because of timing issue Action picker will take some time to reload picker on keyboard

BTW you should change your code here And also implement same in textFieldDidBeginEditing

- (IBAction)priorityClicked:(id)sender {
    [_priorityTextField resignFirstResponder];

    if (!_priorityArray||![_priorityArray count]) {
        _priorityTextField.text=NSLocalizedString(@"Not Available",nil);
        priority_id=0;

    }else{
        [ActionSheetStringPicker showPickerWithTitle:@"Select Priority" rows:_priorityArray initialSelection:0 target:self successAction:@selector(priorityWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:sender];
    }

}

In the else part you should call showPickerWithTitle method after some delay like below

else{
  [self performSelector:@selector(openPickerWithDelay:) withObject:sender afterDelay:0.5]; // Change 0.5 to whatever you want.

}

Add new method

-(void) openPickerWithDelay:(id) sender {
        [ActionSheetStringPicker showPickerWithTitle:@"Select Priority" rows:_priorityArray initialSelection:0 target:self successAction:@selector(priorityWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:sender];

}

Otherwise you can delay by

double delayInSeconds = 0.5; // Change 0.5 to whatever you want.
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

// Do your stuff here

});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!