从目标c中的数组项自动完成txtfield [英] AutoComplete txtfield from array items in Objective c

查看:78
本文介绍了从目标c中的数组项自动完成txtfield的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本字段,每当用户键入它时,它就会在 tableView 中显示来自数组的相关项以选择其中任何一项,但是当用户使用小关键字键入任何内容时,它不会显示数组。当用户以大写字母输入任何单词作为数组存储时,它会显示该数组。

I have a textfield in which whenever user type it shows related items from array in tableView to select any of them but when user type anything in small keyword it does not show the array. when user enter any word in capital letters as store in an array it shows the array.

我希望当用户以小写或大写字母输入任何单词时,都应显示包含数组的表视图。以下是我的代码,

i want that when user enter any word whether in small or capital letter it should show the table view containing array. Following is my code,

    -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    NSLog(@"Range:%@",NSStringFromRange(range));
    NSLog(@"%@",textField.text);

    NSString *passcode = [textField.text stringByReplacingCharactersInRange:range withString:string];

    NSLog(@"%@",passcode);


    NSPredicate *predicate = [NSPredicate predicateWithFormat: @"SELF CONTAINS %@",passcode];

    carArray = [_staticCarArray filteredArrayUsingPredicate:predicate];

    city = [_staticCarArrays filteredArrayUsingPredicate:predicate];


    NSLog(@"%@", carArray);
    NSLog(@"%@", city);


    if ([carArray count]==0) {
        _carTable.hidden = TRUE;
    }else{
        _carTable.hidden = FALSE;
    }

    if ([city count]==0) {
        _autotable.hidden = TRUE;
    }else{
        _autotable.hidden = FALSE;
    }

    [_carTable reloadData];
    [_autotable reloadData];


    return TRUE;

}


推荐答案

敏感搜索替换

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"SELF CONTAINS %@",passcode];

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"SELF CONTAINS[c] %@",passcode];

此处,[c]表示不区分大小写的比较。

Here, [c] indicates case insensitive comparison.

这篇关于从目标c中的数组项自动完成txtfield的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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