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 9097849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:13:09+00:00 2026-06-17T00:13:09+00:00

my tableview changes values when I scroll up or down. It seems to use

  • 0

my tableview changes values when I scroll up or down. It seems to use the same values from other parts of the table. I imagine its an error in my cell creation, here is the code.
Please tell me what I did wrong, thank you!

EDITED ADDED WHOLE CODE

//global indexpath to remember which cell tapped
NSIndexPath *globalPath;
@interface SearchViewController ()

@end

@implementation SearchViewController

//Load implementation once per launch
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self linkInputTableToDelegate];
    _temporaryResultsArray =[[NSMutableArray alloc]init];
    _flurryArray=[[NSMutableArray alloc]init];
    _numberOfSections=6;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:NO];
    [InputTable reloadData];

    textFromUserDefaults=[[[HelperMethods alloc]init]getObjectUserDefault:@"textFiltered"];
    [self addTextToFlurryArrayForFlurryAndSavedLists:_textFromUserDefaults];



}
-(void)viewDidDisappear:(BOOL)animated{

}

- (IBAction)searchButtonPressed:(UIButton *)sender {
     self.tabBarController.selectedIndex = 1;
}


//Makes the input table respond to delegate table view methods
-(void)linkInputTableToDelegate{
    _inputTable.dataSource=self;
    _inputTable.delegate=self;
}

-(void)performSearch:(NSString*)text{
    //do search
}

#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    int numberOfRows=_numberOfSections;

    //Rows for iPhone 4
    if ([[UIScreen mainScreen]bounds].size.height==480) {
        numberOfRows=numberOfRows;
        //Rows for iPhone 5
    }else if ([[UIScreen mainScreen]bounds].size.height==568){
        numberOfRows=numberOfRows+1;
    }
    return numberOfRows;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //In reality groups are created with 1 row inside, this is to allow spacing between the rows

    return 1;

}

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];

    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];
    }

    //Is the cell the same as the one clicked when going to ingredient filter
    BOOL cellIndexPathSameAsSelected=[self isCellIndexSameAsPreviousClicked:indexPath];

    cell.textLabel.textColor=[UIColor blackColor];
    if (cellIndexPathSameAsSelected && _textFromUserDefaults!=nil) {

        if (![cell.textLabel.text isEqualToString:_textFromUserDefaults]) {

            cell.textLabel.text=_textFromUserDefaults;
            [self performTextSearch:_textFromUserDefaults];
        }

    }
    return cell;
}

//Compares the previous clicked cell with the cell now selected
-(BOOL)isCellIndexSameAsPreviousClicked: (NSIndexPath*)cellPath{

    if (cellPath.row == globalPath.row && globalPath.section==cellPath.section) {
        return YES;
    }
    else{
        return NO;
    }
}

- (void)updateTableViewWithExtraRow :(NSIndexPath*)rowSelected{
    NSLog(@"number of sections =%i",_numberOfSections);
    if (rowSelected.section == _numberOfSections) {
        _numberOfSections ++;
    }
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellText = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
    [[[HelperMethods alloc]init]saveObjectToUserDefaults:cellText :@"textFiltered"];
    globalPath = indexPath;
    [self updateTableViewWithExtraRow:indexPath];
}

-(void)addTextToFlurryArrayForFlurryAndSavedLists:(NSString*)text{
    if ([_flurryArray count]==0 &&[text length]>0) {
        [_flurryArray addObject:text];
    }
    for (int i=0;i<[_flurryArray count];i++) {
        NSString *textInArray=[_flurryArray objectAtIndex:i];
        if (![textInArray isEqualToString:text]) {
            [_flurryArray addObject:text];
        }

    }
    NSLog(@"Total number of saved items = %i",[_flurryArray count]);
}

// Dispose of any resources that can be recreated.
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
  • 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-06-17T00:13:11+00:00Added an answer on June 17, 2026 at 12:13 am

    The problem is you are only changing the texts in the cells, when those conditions are met. For example, when your cellIndexPathSameAsSelected is NO, you leave the cell unmodified. So you should add an else and do some settings there too.

    EDIT:

    if (cellIndexPathSameAsSelected && _textFromUserDefaults!=nil) {
    
        if (![cell.textLabel.text isEqualToString:_textFromUserDefaults]) {
    
            cell.textLabel.text=_textFromUserDefaults;
            [self performTextSearch:_textFromUserDefaults];
        }
    
    } else {
        cell.textLabel.text = [NSString string];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how to use UISegmentedControl to change datasource in tableview? with sql tables or read
I'm using Core Data and KVO to look for changes in values to trigger
I currently have a UISegmentedControl set to add/remove table view cells when its value
UPDATED : Scroll down for updated. I have a UITableView which cells contain few
New to objective. I am trying to put 2 values into a table view.
I have created a table view that display data from array.but now when i
I have a tableview and a detailview and I can pass data from my
i have 2 buttons A and B both display tableview and data initially same
I want to populate data from database in to a table view in grouped
I have a tableview with UISwitch in each row of the table. Switch is

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.