Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4065962
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:04:44+00:00 2026-05-20T16:04:44+00:00

Guys, i have a little issue here. Im doing a search to my UITableView.

  • 0

Guys, i have a little issue here. Im doing a search to my UITableView. I search “iPhone”, it returns to me one result. Its ok. iPhone just has one result. But when i search for iPad, that has two results, it gives me 2 results, but the first row stills displaying iphone info. The second display the iPad correct information.

When i click on search bar again to search another word, it gives me the two desired rows of ipad. But when i press the cancel button, it returns to the iPhone and iPad rows.

What im doing wrong?

Thanks

Cell and Table Methods:

        - (NSInteger)tableView:(UITableView *)tableView
         numberOfRowsInSection:(NSInteger)section {
            return [self.listCod count];
        }




        - (UITableViewCell *)tableView:(UITableView *)tableView
                 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
            static NSString *MyIdentifier = @"SearchResult";
            UITableViewCell *cell = [tableView
                                     dequeueReusableCellWithIdentifier:MyIdentifier];

            if (cell == nil) {
                cell =
                [[[UITableViewCell alloc]
                  initWithFrame:CGRectMake(0, 0, 180, 200)
                  reuseIdentifier:MyIdentifier]
                 autorelease];


            UIColor *bkgColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"SearchViewTableCellBackground.png"]];

            UIView* backgroundView = [ [ [ UIView alloc ] initWithFrame:CGRectZero ] autorelease ];
            backgroundView.backgroundColor = bkgColor;
            cell.backgroundView = backgroundView;

            // Foto do produto

            UIView *teste = [[UIView alloc] init];
            teste.frame = CGRectMake(5, 5, 100, 100);
            teste.backgroundColor = [UIColor blueColor];
            [cell addSubview:teste];


            // Label de Marca

            UILabel *marca = [[UILabel alloc] init];
            marca.frame = CGRectMake(115, 10, 195, 25);
            marca.backgroundColor = [UIColor clearColor];
            marca.textColor = [UIColor grayColor];
            NSString *marcaString = [self.listMarca objectAtIndex:indexPath.row];
            marca.font = [UIFont systemFontOfSize:13.0];
            marca.text = marcaString;
            [cell addSubview:marca];
            [marca release];


            // Label do nome do produto

            UILabel *nome = [[UILabel alloc] init];
            nome.frame = CGRectMake(115, 30, 195, 25);
            nome.backgroundColor = [UIColor clearColor];
            nome.textColor = [[UIColor alloc] initWithRed:26.0 / 255 green:177.0 / 255 blue:240.0 / 255 alpha:1.0];

            nome.font = [UIFont boldSystemFontOfSize:25.0];
                NSString *noemString = [self.listName objectAtIndex:indexPath.row];
                nome.text = noemString;
            [cell addSubview:nome];
            [nome release];

            //Preco

            UILabel *preco = [[UILabel alloc] init];
            preco.frame = CGRectMake(115, 55, 195, 25);
            preco.backgroundColor = [UIColor clearColor];
            preco.textColor = [UIColor grayColor];


            // Manda preco e parcela pra tratar

            [self priceFormat:[self.listPreco objectAtIndex:indexPath.row] :[self.listParcela objectAtIndex:indexPath.row]];


            preco.font = [UIFont boldSystemFontOfSize:20.0];
            preco.text = self.precoFinal;
            [cell addSubview:preco];


            //Parcela

            UILabel *parcelaLabel = [[UILabel alloc] init];
            parcelaLabel.frame = CGRectMake(115, 73, 195, 25);
            parcelaLabel.backgroundColor = [UIColor clearColor];
            parcelaLabel.textColor = [UIColor grayColor];
            parcelaLabel.font = [UIFont systemFontOfSize:13.0];
            parcelaLabel.text = self.parcelamentoFinal;

            [cell addSubview:parcelaLabel];

            }



            return cell;
        }

And the search bar methods:

            - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
                [searchBar setShowsCancelButton:YES animated:YES];
                self.theTableView.allowsSelection = NO;
                self.theTableView.scrollEnabled = NO;
                [theTableView setRowHeight:110];
            }

            - (void)searchDisplayController:(UISearchDisplayController *)controller
             willShowSearchResultsTableView:(UITableView *)tableView
            {
                [tableView setRowHeight:[[self theTableView] rowHeight]];
                tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
                [self.tableData removeAllObjects];
                [self.theTableView reloadData];
            }

            - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
                searchBar.text=@"";

                [searchBar setShowsCancelButton:NO animated:YES];
                [searchBar resignFirstResponder];
                self.theTableView.allowsSelection = YES;
                self.theTableView.scrollEnabled = YES;
            }


            - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
                return NO;
            }

            - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {

                // Converte a String do campo de busca

                NSString* buscaGet =
                [searchBar.text stringByAddingPercentEscapesUsingEncoding:
                 NSASCIIStringEncoding];    


                // Conecta com a URL


                NSString *endereco = [[NSString alloc] initWithFormat:@"http://localhost/icomm/test.php?nome=%@", buscaGet];

                // Lê o resultado

                TBXML * tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:endereco]] retain];
                TBXMLElement * rootXMLElement = tbxml.rootXMLElement;


                TBXMLElement * item = [TBXML childElementNamed:@"produto" parentElement:rootXMLElement];

                listCod = [[NSMutableArray alloc] init];

                listMarca = [[NSMutableArray alloc] init];

                listName = [[NSMutableArray alloc] init];

                listPreco = [[NSMutableArray alloc] init];

                listParcela = [[NSMutableArray alloc] init];

                while (item) {


                    // Seta a id do produto

                    TBXMLElement * codigo = [TBXML childElementNamed:@"item" parentElement:item];
                    NSString * codProd = [TBXML textForElement:codigo];

                    [self.listCod addObject:codProd];


                    // Seta a marca do produto

                    TBXMLElement * marca = [TBXML childElementNamed:@"marca" parentElement:item];
                    NSString * marcaProd = [TBXML textForElement:marca];    
                    [self.listMarca addObject:marcaProd];

                    // Seta o nome do produto

                    TBXMLElement * nome = [TBXML childElementNamed:@"nome" parentElement:item];
                    NSString * nomeProd = [TBXML textForElement:nome];
                    [self.listName addObject:nomeProd];


                    // Seta o preco do produto

                    TBXMLElement * preco = [TBXML childElementNamed:@"preco" parentElement:item];
                    NSString * precoProd = [TBXML textForElement:preco];    
                    [self.listPreco addObject:precoProd];



                    // Seta o parcela do produto

                    TBXMLElement * parc = [TBXML childElementNamed:@"parcela" parentElement:item];
                    NSString * parcProd = [TBXML textForElement:parc];
                    [self.listParcela addObject:parcProd];




                    // Procura o proximo produto.

                    item = [TBXML nextSiblingNamed:@"produto" searchFromElement:item
                            ];
                }


                NSLog(@"%@", self.listName);

                [searchBar setShowsCancelButton:NO animated:YES];
                [searchBar resignFirstResponder];
                self.theTableView.allowsSelection = YES;
                self.theTableView.scrollEnabled = YES;

                //Remove tudo da table e recarrega

                [[[self searchDisplayController] searchResultsTableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

                [tableData removeAllObjects];
                [theTableView reloadData];

            }

Thanks for all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:04:45+00:00Added an answer on May 20, 2026 at 4:04 pm

    You are only setting your labels up inside the if (cell == nil) part of your code. This only gets called the first time a cell is created; after that the cell is dequeued for reuse and you don’t create a new cell. If you want to dequeue your cells like that, you need to set the text (and any other property of the label that might change) outside of that if statement. In order to get references to your labels, you will need to use tags and viewWithTag:.

    Or if you want to simplify things, don’t dequeue your tableCells; though this could lead to performance issues if you have a lot of cells.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I have a little issue here. I have a panel where I
Hey guys, I have a little issue here. I need my users to be
Hey guys, have a little issue i need to figure out. I created a
Ok guys just a small game: I have some specifications for a project. At
Hey guys, I have a little button functionality that is not erring, but also
Hi Guys I have a fully functioning query, but need to do a little
When reading about SQL Injection and XSS i was wondering if you guys have
How have you guys handled working with jQuery includes <script type=text/javascript src=jquery.js></script> in Asp.Net
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have you guys and gals got any tips or hacks for making the most

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.