使用 uisearchbar 在 uitableview 中搜索时键盘卡住了...? [英] keyboard stuck when searching in uitableview using uisearchbar...?

查看:29
本文介绍了使用 uisearchbar 在 uitableview 中搜索时键盘卡住了...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 uitableview 和 uisearchbar.我正在绑定带有大量记录的表,并为用户提供可以从中进行搜索的功能.但是很多时候当数据大小很大时,键盘会卡住,直到它重新加载表.无论如何,我可以异步搜索.这是 iOS 4 应用.

I have a uitableview and uisearchbar. I'm binding table with tons of records and give functionality to user can search from that. But many times when data size is large keyboard stuck uptill it reload the table. Is it anyway so I can asynchronously search. It's iOS 4 app.

我的 uisearchbar textDidChange 方法如下

my uisearchbar textDidChange method is as below

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
if(searchText.length == 0)
{
    isFiltered = FALSE;
}
else
{
    @autoreleasepool {
        isFiltered = true;
        membersMFilterArray = [[NSMutableArray alloc] init];
        int lineCount = [[[membersMArray objectAtIndex:0] valueForKey:@"LineCount"] intValue];
        NSString *membersMArrayValue;
        for (int i=0; i<[membersMArray count]; i++)
        {
            membersMArrayValue = [membersMArray objectAtIndex:i];
            NSString *line;
            for (int j=0; j<lineCount; j++)
            {
                line = [NSString stringWithFormat:@"Line%d",j+1];
                NSRange lineRange = [[membersMArrayValue valueForKey:line] rangeOfString:searchText options:NSCaseInsensitiveSearch];
                if(lineRange.location != NSNotFound)
                {
                    [membersMFilterArray addObject:[membersMArray objectAtIndex:i]];
                    break;
                }
            }
        }
    }
}

[tblMember reloadData];}

我的数组如下,我从中搜索,实际上这是一个用户数据,出现在一个表行中,如果有 10000 行,则乘以这个.所以上面的for循环我认为是因为这种方式.

my array is as below from which I've search, Actually this is one user data which arrise in one table row and if there is 10000 rows then multiply with this. So above for loop is I think as because of this way.

(
    {
    Line1 = "Ashish";
    Line10 = "Ahmedabad";
    Line11 = "Gujarat";
    Line12 = "";
    Line13 = "India";
    Line14 = "";
    Line15 = "";
    Line16 = "abc@yahoo.com";
    Line17 = "";
    Line18 = "";
    Line19 = "xyz";
    Line2 = "Ahmedabad, Gujarat";
    Line20 = "Jun 04, 2012";
    Line3 = "";
    Line4 = "";
    Line5 = "";
    Line6 = "abc";
    Line7 = "xyz";
    Line8 = "";
    Line9 = "";
    LineCount = 20;
    "Member_id" = GM00018004;
    RowNo = 01;
}

)

推荐答案

从你的代码来看,我认为 两个 for 循环是不必要的.使用更好的概念对数组项进行排序.

From your code, i think the two for loops are unnecessary. Use better concept to sort the array items.

我对加速的一些建议.

Remove the auto-release-pool     
Use one for-loop instead of two

您可以查看开始&执行的结束时间使用 NSlog.发现所用的时间进程并修复它.

You can check it out the start & end time of execution using NSlog.Discover the time taken process and fix it.

示例:

NSLog(@"loop1 started now")
for (int i=0; i<[membersMArray count]; i++)
        {
            membersMArrayValue = [membersMArray objectAtIndex:i];
            NSString *line;
            for (int j=0; j<lineCount; j++)
            {

                NSLog(@"loop2 started now")
                line = [NSString stringWithFormat:@"Line%d",j+1];
                NSRange lineRange = [[membersMArrayValue valueForKey:line] rangeOfString:searchText options:NSCaseInsensitiveSearch];
                if(lineRange.location != NSNotFound)
                {
                    [membersMFilterArray addObject:[membersMArray objectAtIndex:i]];
                    break;
                }
            }  

         NSLog(@"loop2 ended now")
        }

NSLog(@"loop1 ended now")

这篇关于使用 uisearchbar 在 uitableview 中搜索时键盘卡住了...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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