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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:57:48+00:00 2026-05-24T07:57:48+00:00

I’ve created a feature in my app that loads a custom cell when tapping

  • 0

I’ve created a feature in my app that loads a custom cell when tapping the cell. tapping the cell will show the extra buttons and tapping again will hide it, no problem with that. however, I think I have a cell reuse issue here when tapping rows next to the currently selected row. look at the screenshot, I tap North California then the buttons show up, when I tap Ethiopia the result is the second screenshot.

http://i228.photobucket.com/albums/ee262/romano2717/reuse.jpg

here’s the code

    if(selectedIndexPath != nil && [selectedIndexPath isEqual:indexPath]) {
    selectedIndex = indexPath.row;
    NSLog(@"selectedIndex %d",selectedIndex);
    static NSString *CustomCellIdentifier = @"CustomCell";
    CustomCell *customCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
    if (customCell == nil) { 
        customCell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier] autorelease];
    }
    customCell.locationLabelOutlet.text = [usgsFeeds objectAtIndex:[indexPath row]];
    customCell.dateLabelOutlet.text = [pubDateArr objectAtIndex:[indexPath row]];

    float thisMag;
    thisMag = [(NSNumber *)[magnitudeArr objectAtIndex:[indexPath row]] floatValue];
    customCell.magnitudeImageOutlet.image = [self imageForMagnitude:thisMag];
    [customCell setSelectionStyle:UITableViewCellSelectionStyleNone];

    return customCell;
}

else{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    if (cell == nil) {
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        locationLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, 225, 20)] autorelease];
        locationLabel.tag = kLocationLabelTag;
        locationLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0];
        locationLabel.backgroundColor = [UIColor clearColor];
        [cell.contentView addSubview:locationLabel];

        //same as above will follow
    }
    else{
        locationLabel = (UILabel *)[cell.contentView viewWithTag:kLocationLabelTag];
        dateLabel = (UILabel *)[cell.contentView viewWithTag:kDateLabelTag];
        magnitudeImage = (UIImageView *)[cell.contentView viewWithTag:kMagnitudeImgTag];
    }
    locationLabel.text = [usgsFeeds objectAtIndex:[indexPath row]];
    dateLabel.text = [pubDateArr objectAtIndex:[indexPath row]];

    float thisMag;
    thisMag = [(NSNumber *)[magnitudeArr objectAtIndex:[indexPath row]] floatValue];
    magnitudeImage.image = [self imageForMagnitude:thisMag];

    return cell;
}

and this is my custom cell

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:
    (NSString    *)reuseIdentifier
    {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    locationLabelOutlet = [[UILabel alloc] initWithFrame:CGRectMake(10, 3, 210, 17)];
    locationLabelOutlet.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0];
    locationLabelOutlet.backgroundColor = [UIColor clearColor];
    //and other outlets
    [thisContainer addSubview:locationLabelOutlet];
    [thisContainer addSubview:magnitudeImageOutlet];
    [thisContainer addSubview:dateLabelOutlet];

    [buttonsView addSubview:locButton];
    [buttonsView addSubview:detButton];
    [buttonsView addSubview:shabutton];
    [buttonsView addSubview:favButton];

    [thisContainer addSubview:buttonsView];
    [self.contentView addSubview:thisContainer];

this is for the did select

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
    (NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    selectedIndexPath = indexPath; 

    if(selectedIndex == indexPath.row)
    {
    selectedIndexPath = nil;
    [tableView reloadRowsAtIndexPaths:
    [NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    selectedIndex = -1;
    return;
    }

    if(selectedIndexPath != nil && [selectedIndexPath isEqual:indexPath]) {
    [tableView reloadRowsAtIndexPaths:
    [NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
    }
  • 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-24T07:57:49+00:00Added an answer on May 24, 2026 at 7:57 am

    Well, maybe it’s because you didn’t reload the previously selected cell at selectedIndexPath.

    I guess your code works when you tap twice on the same row.

    I will comment directly on the code in the tableView:didSelectRowAtIndexPath: method:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
    {
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
        //added the following if() part
        if(selectedIndex != -1 && selectedIndex != indexPath.row && selectedIndexPath != nil)
        {
            [tableView reloadRowsAtIndexPaths:
            [NSArray arrayWithObject:selectedIndexPath] withRowAnimation:UITableViewRowAnimationFade];
        }
    
        selectedIndexPath = indexPath;
    
        if(selectedIndex == indexPath.row)
        {
            selectedIndexPath = nil;
            [tableView reloadRowsAtIndexPaths:
            [NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            selectedIndex = -1;
            return;
        }
    
        if(selectedIndexPath != nil && [selectedIndexPath isEqual:indexPath])
        {
            [tableView reloadRowsAtIndexPaths:
            [NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        }
    }
    

    I hope it’ll work.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload

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.