UITextView与ActionSheetStringPicker Picker视图有关 [英] UITextView issue with ActionSheetStringPicker Picker view

查看:81
本文介绍了UITextView与ActionSheetStringPicker Picker视图有关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请先在此处检查3个屏幕截图.

Check 3 screenshots here first.

屏幕截图1:主题为UITextview字段.当我点击主题文本字段时,将出现普通键盘.现在这里没有问题.

Screenshot 1 : Subject is UITextview field. When I tap on subject text field normal keyboard will come. There is no problem here now.

截屏2:优先级是UITextfield视图.在这里,我使用UIActionsheet Picker视图.当我单击优先级"时,文本字段选择器将出现,如屏幕截图所示.这也很好.

Screenshot 2 : Priority is UITextfield view. Here I use UIActionsheet Picker view. When I click on Priority textfield picker will appear as shown in screenshot. This is also working fine.

我的问题:当我直接通过滚动而不是使用完成按钮或键盘上的下一个按钮通过滚动单击主题文本视图中的优先级文本字段时.然后下一个问题来了.

My Problem : When I click Priority textfield directly from Subject textview by scrolling without using done button or next button from keyboard. Then following issue is arriving.

或者当我将UITextview移到其他任何其他文本字段(如帮助主题"文本字段或源文本"字段(在此文本字段中使用UIActionsheet.)中)时,出现相同的问题.

or when I move UITextview to other any other Text Field like in Help Topic Text Field or Source Text Field (In this text field UIActionsheet is used.) same problem is arriving.

请参阅屏幕截图3.

在这里,键盘和UIActionsheet都出现.这里键盘没有隐藏,它仍然出现.当我将UITextView移到下一个文本字段(即UIActionsheet选择器中)时,它不会显示在此处,它仅显示Picker View.

here, keyboard and UIActionsheet both are appearing. Here keyboard is not hiding, it is still appearing. It will not appear here, when I move here UITextView to next Text Field i.e in UIActionsheet picker, it has show Picker VIew only.

我没有得到什么问题.有人请告诉我解决方案.

What is the problem I am not getting. Anybody please tell me solution for that.

这是一些代码,

@interface EditDetailTableViewController ()
{
    NSNumber *help_topic_id;
    NSNumber *priority_id;



    NSMutableArray * pri_idArray;
    NSMutableArray * helpTopic_idArray;
}

- (void)helpTopicWasSelected:(NSNumber *)selectedIndex element:(id)element;
- (void)priorityWasSelected:(NSNumber *)selectedIndex element:(id)element

- (void)actionPickerCancelled:(id)sender;
@end

@implementation EditDetailTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    help_topic_id=[[NSNumber alloc]init];
    priority_id=[[NSNumber alloc]init];
}

-(void)removeKeyBoard
{
    [self.subjectTextView resignFirstResponder];
}

- (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];
    }

}

- (IBAction)helpTopicClicked:(id)sender {
    [_helpTopicTextField resignFirstResponder];

    if (!_helptopicsArray||!_helptopicsArray.count) {
        _helpTopicTextField.text=NSLocalizedString(@"Not Available",nil);
        help_topic_id=0;
    }else{
        [ActionSheetStringPicker showPickerWithTitle:@"Select Helptopic" rows:_helptopicsArray initialSelection:0 target:self successAction:@selector(helpTopicWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:sender];
    }

}

- (void)priorityWasSelected:(NSNumber *)selectedIndex element:(id)element {
    priority_id=(pri_idArray)[(NSUInteger) [selectedIndex intValue]];

    //self.selectedIndex = [selectedIndex intValue];

    //may have originated from textField or barButtonItem, use an IBOutlet instead of element
    self.priorityTextField.text = (_priorityArray)[(NSUInteger) [selectedIndex intValue]];
}

- (void)helpTopicWasSelected:(NSNumber *)selectedIndex element:(id)element {
    help_topic_id=(helpTopic_idArray)[(NSUInteger) [selectedIndex intValue]];
    // self.selectedIndex = [selectedIndex intValue];

    //may have originated from textField or barButtonItem, use an IBOutlet instead of element
    self.helpTopicTextField.text = (_helptopicsArray)[(NSUInteger) [selectedIndex intValue]];
}


#pragma mark - UITextFieldDelegate

- (void)textFieldDidBeginEditing:(UITextField *)textField {

if (textField.tag==1) {

        [_priorityTextField resignFirstResponder];
         _priorityTextField.tintColor = [UIColor clearColor];

        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:self.view];
        }

        // return NO;
    }else if(textField.tag==2){
        //[_subjectTextField resignFirstResponder];
        [_helpTopicTextField resignFirstResponder];
         _helpTopicTextField.tintColor = [UIColor clearColor];

        if (!_helptopicsArray||!_helptopicsArray.count) {
            _helpTopicTextField.text=NSLocalizedString(@"Not Available",nil);
            help_topic_id=0;
        }else{
            [ActionSheetStringPicker showPickerWithTitle:@"Select Helptopic" rows:_helptopicsArray initialSelection:0 target:self successAction:@selector(helpTopicWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:self.view];
        }
        // return NO;
    }else{

    }
    // return YES;
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}


- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{

    //[textView resignFirstResponder];

    if(textView == _subjectTextView)
    {

        if([text isEqualToString:@" "])
        {
            if(!textView.text.length)
            {
                return NO;
            }
        }

        if([textView.text stringByReplacingCharactersInRange:range withString:text].length < textView.text.length)
        {

            return  YES;
        }

        if([textView.text stringByReplacingCharactersInRange:range withString:text].length >100)
        {
            return NO;
        }

        NSCharacterSet *set=[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "];


        if([text rangeOfCharacterFromSet:set].location == NSNotFound)
        {
            return NO;
        }
    }


    return YES;
}




@end

推荐答案

我认为以下IBAction代码:

- (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.

这篇关于UITextView与ActionSheetStringPicker Picker视图有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆