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

  • SEARCH
  • Home
  • 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 6729005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:14:14+00:00 2026-05-26T10:14:14+00:00

I have a tableview that contains cell images and names as text. At the

  • 0

I have a tableview that contains cell images and names as text. At the top i have added a searchbar. And when I search i am able to do the search for names, but the images are still the same. How can change the images also, as per the changes in names when search?
this code in the tableview delegate, and i’m using some search delegate methods also. I haven’t done anything to arrange the images with respect to the names. I need help to implement that.

if(searching)
        cell.textLabel.text = [copyListOfItems objectAtIndex:indexPath.row];
    else {

        [cell.imageView setImageWithURL:[NSURL URLWithString:[imageArray objectAtIndex:indexPath.row]]  
                   placeholderImage:[UIImage imageNamed:@"defaultPerson.png"]];
        cell.textLabel.text = [friendsList objectAtIndex:indexPath.row];        
    }

Here is few more code:

- (void) searchTableView {

    NSString *searchText = searchBar.text;
    NSMutableArray *searchArray = [[NSMutableArray alloc] init];


    for (NSString *sTemp in friendsList)
    {
        NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];

        if (titleResultsRange.length > 0)
            [copyListOfItems addObject:sTemp];
    }

    [searchArray release];
    searchArray = nil;
}

Thanks.

  • 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-26T10:14:15+00:00Added an answer on May 26, 2026 at 10:14 am

    It seems to me that you are not updating your cells correctly.

    A simple [myTableView reloadData]; might help, but you might also want to consider looking into the way you are adding the imageViews to you cells. You might not have removed(/released/nilled) the imageViews you place on top of your cells correctly. You have to do this everytime you update your cells as well since the imageViews won’t do this themselves unless you specifically told them so.

    When you updated your question with some helpful code I can be more specific about this concerning your problem.


    Now that you did edit your post with some (although very little amount of) code I can see from this snippet that you are not updating your cell.imageViews to the new list of objects.

    You updated your uitableview with the new “copyListOfItems” but you didn’t do that same thing for your images resulting in the display of the old content which are the images from “imageArray”

    You need to make a similar array for your images as you did with the text.

    if(searching)
    {
        cell.textLabel.text = [copyListOfItems objectAtIndex:indexPath.row];
        [cell.imageView setImageWithURL:[NSURL URLWithString:[searchedArrayOfImages objectAtIndex:indexPath.row]];  
    }
    else {
    
        [cell.imageView setImageWithURL:[NSURL URLWithString:[imageArray objectAtIndex:indexPath.row]]  
                   placeholderImage:[UIImage imageNamed:@"defaultPerson.png"]];
        cell.textLabel.text = [friendsList objectAtIndex:indexPath.row];        
    }
    

    A better way (i.m.o.) to save images to names is making a NSDictionary for them so when you pick a record your name always fits your image.


    In regards of the comments below:
    At the moment you search, mostlikely in the textDidChange delegate method, you mostlikely pick the indexrows of all your search matches. At the moment you pick the index of a hit from “friendlist” and put it into “copyListOfItems” you also need to use the very same index and take the image from “imageArray” and put them into “searchedArrayOfImages”. This way you build both your text- and image array the same way. Then when you reload your tableview you can take the same index from “copyListOfItems” and from “searchedArrayOfImages” and populate your cell properly.


    It would look something like this:

    - (void) searchTableView 
    {
    
        NSString *searchText = searchBar.text;
        NSMutableArray *searchArray = [[NSMutableArray alloc] init];
    
        int indexCount = 0; //keeps track of which index you are at.
        for (NSString *sTemp in friendsList)
        {
            NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
    
            if (titleResultsRange.length > 0)
            {
                [copyListOfItems addObject:sTemp]; //this is your name result
                [searchedArrayOfImages addObject:[imageArray objectAtIndex:indexCount]]; //adds image that fits with the nameresult to array of searched images
            }
    
            indexCount++;
        }
    
        [searchArray release];
        searchArray = nil;
    }
    

    When you are done searching the cells will be updated like this (according to your snippet)

    if(searching)
    {
        cell.textLabel.text = [copyListOfItems objectAtIndex:indexPath.row];
        [cell.imageView setImageWithURL:[NSURL URLWithString:[searchedArrayOfImages objectAtIndex:indexPath.row]];  
    }
    else 
    {
    
        [cell.imageView setImageWithURL:[NSURL URLWithString:[imageArray objectAtIndex:indexPath.row]]  
                   placeholderImage:[UIImage imageNamed:@"defaultPerson.png"]];
        cell.textLabel.text = [friendsList objectAtIndex:indexPath.row];        
    }
    

    This should suffice^^ good luck.

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

Sidebar

Related Questions

I have a tableview which contains images in cell. If I touch an image
I have a tableview, one of the rows contains a cell that contains a
i have one tableview that have custom cells and one cell contains uiimageview,uilabels .
I have a controller that contains a tableView that spawns another controller modally to
I have a tableview with large images that fill the cells and the row
I have a Tableview containing cells with images, however the cells that are reused
I have UITableView that contains many cell. User can expand cell to see more
I have a tableview with a section that contains a list of sounds the
I have a custom cell that contains a button in a table view. The
I have a page that contains a tableview - and a textfield and button

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.