【问题标题】:UITextField give suggetion when typingUITextField 在输入时给出建议
【发布时间】:2023-04-10 19:28:01
【问题描述】:

就像在谷歌中我们写“ahe”它会显示建议就像下面的截图。当我们打字时,我的 iPhone UITextField 怎么可能?

【问题讨论】:

标签: iphone ios uitextfield


【解决方案1】:

你试试这个:

https://github.com/keyf/AutocompletionTableView/downloads

这也是-

最简单的方法是创建一个方法并将其与带有事件 UIControlEventEditingChanged 的​​ UiTextfield 连接,这将为您提供在文本字段中输入的每个字符的跟踪。

[self.selectedTextField addTarget:self action:@selector(enterInLabel ) forControlEvents:UIControlEventEditingChanged];


-(void)enterInLabel 
{ 
selectedLabel.text=selectedTextField.text;
}

【讨论】:

    【解决方案2】:

    添加自我委托方法,当 yourTextField 发生任何变化时将调用该方法。

    [yourTextField addTarget:self action:@selector(textFieldDidChange) forControlEvents:UIControlEventEditingChanged];
    
    
    - (void)textFieldDidChange
    {
        //you may need to call [resultArray removeAllObjects] to get fresh list of cities here.
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"City like[cd] %@",[NSString stringWithFormat:@"*%@*", yourTextField.text]];
        resultArray = [[cityArray filteredArrayUsingPredicate:predicate] mutableCopy];
    }
    

    附:这里,cityArray 包含城市列表,resultArray 返回 NSMutableArray 类型的过滤城市列表。另外,NSPredicateCity 是我正在执行搜索操作的字段。

    【讨论】:

      猜你喜欢
      • 2015-02-13
      • 2014-01-12
      • 1970-01-01
      • 2011-02-14
      • 2011-10-04
      • 1970-01-01
      • 2023-01-18
      • 2022-01-25
      • 1970-01-01
      相关资源
      最近更新 更多