UIsearch栏不将数据返回到表

编程入门 行业动态 更新时间:2024-10-10 04:24:55
本文介绍了UIsearch栏不将数据返回到表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

修改代码

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{静态 NSString *CellIdentifier = @"Cell";UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];如果(单元格==零)cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault重用Identifier:CellIdentifier];如果(被过滤){int rowCount=indexPath.row;Aves *filtrada=[filteredTableData objectAtIndex:rowCount];cell.textLabel.text=filtrada.name;NSLog(@"mostrando:");}别的 {int rowCounter=indexPath.row;Aves *author=[theauthors objectAtIndex:rowCounter];cell.textLabel.text=author.name;}NSLog(@"mostrando:");返回单元格;

}

-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text{如果(文本.长度== 0){isFiltered = FALSE;}别的{isFiltered = true;国际我;[filteredTableData removeAllObjects];for(i=0;[作者数]>i;i++){Aves *name=[theauthors objectAtIndex:i];//NSLog(name.name);NSRange nameRange = [[name.name lowercaseString] rangeOfString:[text lowercaseString]];if(nameRange.length>0){[filteredTableData addObject:name];NSLog(name.name);}}[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];}}

经过一段时间的工作后,我解决了一些问题.刚刚更新了我的代码,问题是 tableView 的重绘,其他一切正常.检查它并给出您的任何想法,请^^

再次感谢您.

解决方案

终于修复了.这是我的工作代码,谢谢你们 =)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {静态 NSString *CellIdentifier = @"Cell";UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier];如果(isFiltered==TRUE){int rowCount=indexPath.row;//for (rowCount=0; rowCount<[filteredTableData count]; rowCount++) {Aves *filtrada=[filteredTableData objectAtIndex:rowCount];cell.textLabel.text=filtrada.name;//}}else if(isFiltered==FALSE){int rowCounter=indexPath.row;Aves *author=[theauthors objectAtIndex:rowCounter];cell.textLabel.text=author.name;}返回单元格;}

<块引用>

-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text {

 [filteredTableData removeAllObjects];FilteredTableData=[[NSMutableArray alloc]init ];如果(文本.长度== 0){isFiltered = FALSE;}别的{isFiltered = TRUE;国际我;for(i=0;[作者数]>i;i++){Aves * filtrado=[[Aves alloc]init];filtrado=[theauthors objectAtIndex:i];//NSLog(filtrado.name);NSRange nameRange = [[filtrado.name lowercaseString] rangeOfString:[text lowercaseString]];if(nameRange.length>0){[filteredTableData addObject:filtrado];}}[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil

waitUntilDone:NO];}}

Edited code

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell==nil) 
    cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];


if (isFiltered) {
   int rowCount=indexPath.row;
   Aves *filtrada=[filteredTableData objectAtIndex:rowCount];
   cell.textLabel.text=filtrada.name;
   NSLog(@"mostrando: ");
    }else {
        int rowCounter=indexPath.row;
        Aves *author=[theauthors objectAtIndex:rowCounter];
        cell.textLabel.text=author.name;
    }
NSLog(@"mostrando: ");
return cell;

}

-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text
{
    if(text.length == 0)
    {
        isFiltered = FALSE;
    }
    else
    {
        isFiltered = true;
        int i;
        [filteredTableData removeAllObjects];
        for(i=0;[theauthors count]>i;i++)
        {
          Aves *name=[theauthors objectAtIndex:i];
            //NSLog(name.name);
            NSRange nameRange = [[name.name lowercaseString] rangeOfString:[text lowercaseString]];
            if(nameRange.length>0)
            {
                [filteredTableData addObject:name];
                NSLog(name.name);
            }
        }
        [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
    }
}

Edit: After working on it a while I solved some problems.Just updated my code, the problem is the repaint of the tableView, every thing else go ok. Check it and give any ideas you have plz ^^

Thx again for your time.

解决方案

finally fixed it. Here is my working code, thx you all =)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                reuseIdentifier:CellIdentifier];

    if (isFiltered==TRUE) {
        int rowCount=indexPath.row;
        //for (rowCount=0; rowCount<[filteredTableData count]; rowCount++) {
        Aves *filtrada=[filteredTableData objectAtIndex:rowCount];
        cell.textLabel.text=filtrada.name;
        //}

    }else if(isFiltered==FALSE) 
    {
        int rowCounter=indexPath.row;
        Aves *author=[theauthors objectAtIndex:rowCounter];
        cell.textLabel.text=author.name;
    }
    return cell; 
}

-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text {

  [filteredTableData removeAllObjects];

filteredTableData=[[NSMutableArray alloc]init ];

if(text.length == 0)
{
    isFiltered = FALSE;
}
else
{
    isFiltered = TRUE;
    int i;

    for(i=0;[theauthors count]>i;i++)
    {
        Aves * filtrado=[[Aves alloc]init];
        filtrado=[theauthors objectAtIndex:i];
        //NSLog(filtrado.name);
        NSRange nameRange = [[filtrado.name lowercaseString] rangeOfString:[text lowercaseString]];
        if(nameRange.length>0)
        {
            [filteredTableData addObject:filtrado];

        }
    }
    [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil

waitUntilDone:NO]; } }

这篇关于UIsearch栏不将数据返回到表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 01:42:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1182541.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不将   数据   UIsearch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!