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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:18:11+00:00 2026-06-05T23:18:11+00:00

I have Xcode 4.3 and that class doesn’t use ARC. I have created a

  • 0

I have Xcode 4.3 and that class doesn’t use ARC.

I have created a tableview which use a reuseable cells. I have tried to get the answer from others but couldn’t get a proper one.

My table gets the data from an array and I use UILabel to show the data and UIImageView to show an image.

My code is below. It’s long but the idea is to create and put the UILabel, button, and image once and change the data.

On scrolling, only one cell changes (while scrolling I see different data), and the other reused cells show the same data from cell 1.

static NSString * CellIdentifier = @"HistoryCellId";

iImage = [UIImage imageNamed: [NSString stringWithFormat:@"%@.png",[(_searching ? _titleArrCopy : _titleArr) objectAtIndex:indexPath.row]]];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                  reuseIdentifier:CellIdentifier];
    iconImage = [[UIImageView alloc] init];
    UIImage * image = [UIImage imageNamed:@"HFcellBG.png"];
    UIImageView * bgImage = [[UIImageView alloc] initWithImage: image];
    cell.backgroundView = bgImage;
    //[iconImage removeFromSuperview];
    iconImage.image = iImage;
    iconImage.frame = CGRectMake(_iconX, 11, 58, 58);
    //iconImage.backgroundColor = [UIColor whiteColor];
    [cell addSubview:iconImage]; // show the image on the side

    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_titleX, 3, 212, 25)];
    titleLabel.textAlignment = _nibNameRTL ? UITextAlignmentRight : UITextAlignmentLeft;
    [cell addSubview:titleLabel]; // show a title

    timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_dateX, 25, 212, 20)];
    timeLabel.textAlignment = _nibNameRTL ? UITextAlignmentRight : UITextAlignmentLeft;
    timeLabel.font = [UIFont systemFontOfSize:15]; // show another data
    [cell addSubview:timeLabel];

    favoriteBtn = [[UIButton alloc] initWithFrame:CGRectMake(_removeX, 48, 66, 23)];
    favoriteBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [favoriteBtn setTitle:getTextValue(3) forState:UIControlStateNormal];
    [cell addSubview:favoriteBtn];
     // show a button

} 

[iconImage setImage:iImage];

[titleLabel setText:[self parserData:indexPath.row]];

[timeLabel setText:[NSString stringWithFormat:getTextValue(4),[(_searching ? _TimeArrCopy :_TimeArr) objectAtIndex:indexPath.row]]];

if ([[(_searching ? _FavoriteArrCopy : _FavoriteArr) objectAtIndex:indexPath.row] isEqualToString:@"1"]) {
    [favoriteBtn setEnabled:NO];
    [favoriteBtn setBackgroundImage:[UIImage imageNamed:@"HFfavoriteCheckedBtn.png"] forState:UIControlStateNormal];
}
else {
    [favoriteBtn setEnabled:YES];
    [favoriteBtn setBackgroundImage:[UIImage imageNamed:@"HFfavoriteBtn.png"] forState:UIControlStateNormal];
}

favoriteBtn.tag = indexPath.row;
[favoriteBtn addTarget:self action:@selector(addToFavorite:) 
      forControlEvents:UIControlEventTouchUpInside];


//    [cell.favoriteBtn setTitle:getTextValue(3) forState:UIControlStateNormal];
//    [cell.typeImage setImage:iconImage];
//    cell.data = [_dataArr objectAtIndex:indexPath.row];

cell.selectionStyle = UITableViewCellSelectionStyleNone;
// return it
return cell;

}

The data is like below: I can see 5 cells every time and when scrolling I see the behavior below:

1
2
3
4
5 - the cell 5 changes all the time while scrolling
1 - cell one data again
2
etc

When I check the indexPath.row, it is the right row.

What’s wrong?

  • 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-05T23:18:15+00:00Added an answer on June 5, 2026 at 11:18 pm

    The variables you are trying to use to configure the cell are initialized inside an if check that is most likely not true (especially after scrolling, when your cell instance will already exist). You should access properties of the cell object to modify it’s state.

    This is one of the pitfalls of Objective-C allowing you to send messages to nil.

    [titleLabel setText:[self parserData:indexPath.row]];
    

    titleLabel will be nil after you scroll, and there will not be an error.

    If you have a lot of custom UI in your cell, I suggest making a custom subclass, and adding properties for all of the subviews which you need to customize, then use these properties outside of your if(cell == nil) block.

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

Sidebar

Related Questions

i have searched Xcode controls but doesn't found anything that makes a GridView like
I have a table that I created within xcode so there is no nib
I have an application that works fine in an older project (that doesn't use
Setup: I have a custom class I've created that handles data retrieved from a
I have created a template class(TBase) that defines another class(BaseUDT) within its body. #pragma
If I type xcodebuild -version it recognises that I have xcode installed: Xcode 4.3.2
I have installed Xcode 4.3.1. I am looking for the texturetool that is used
I have a 32bit iMac that I am writing an iPhone app in Xcode
I have a problem with SQLite3 on Xcode. the problem is that I have
In XCode 4.2, I have some logic tests that I want to exercise against

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.