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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:54:45+00:00 2026-05-27T05:54:45+00:00

I have a UITableView (on a UIViewController) which is pushed via a navigationController. Along

  • 0

I have a UITableView (on a UIViewController) which is pushed via a navigationController. Along with pushing, I select with which array i want to populate the table. The code for pushing is like this:

if(self.newView == nil)
{
    NewView *viewTwo = [[NewView alloc] initWithNibName:@"Bundle" bundle:[NSBundle mainBundle]];
    self.newView = viewTwo;
    [viewTwo release];
}

[self.navigationController pushViewController:self.newView animated:YES];
newView.tableArray=newView.arrayWithOptionOne;
[newView.tableView reloadData];

All works well and the table gets reloaded every time. However in the last row of section 0, there is a switch which loads section 1.
The last row of section 1 is tappable (didSelect…) and it loads a modalView. On this last rod I added a disclosure indicator and also the blue background when tapping. The table has sliders, labels, etc. So the customization is quite long:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell = nil;


static NSString *kDisplayCell_ID = @"DisplayCellID";

cell = [tableView dequeueReusableCellWithIdentifier:kDisplayCell_ID];

if (cell == nil)
    {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:kDisplayCell_ID] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
else
    {

    UIView *viewToRemove = nil;
    viewToRemove = [cell.contentView viewWithTag:1];
    if (viewToRemove)
        [viewToRemove removeFromSuperview];

    UIView *viewToRemove2 = nil;
    viewToRemove2 = [cell.contentView viewWithTag:2];
    if (viewToRemove2)
        [viewToRemove2 removeFromSuperview];


 }


    if (indexPath.section==0) {
        UIControl *cellValueS = [[[arrayTable objectAtIndex:indexPath.section] objectForKey:kViewKey] objectAtIndex:indexPath.row];
        [cell.contentView addSubview:cellValueS];
    }

    if (indexPath.section==0 && indexPath.row==3) {
        UIControl *cellValueL = [[[arrayTable objectAtIndex:indexPath.section] objectForKey:kViewLabel] objectAtIndex:0] ;
        [cell.contentView addSubview:cellValueL];
    }

    if (indexPath.section==1 && indexPath.row==0){
        UIControl *cellValueS = [[[arrayTable objectAtIndex:indexPath.section] objectForKey:kViewKey] objectAtIndex:indexPath.row] ;
        [cell.contentView addSubview:cellValueS];
    } 

    if (indexPath.section==1 && indexPath.row==1) {
        UIControl *cellValueS = [[[arrayTable objectAtIndex:indexPath.section] objectForKey:kViewKey] objectAtIndex:indexPath.row] ;
        [cell.contentView addSubview:cellValueS];

        UIControl *cellValueL = [[[arrayTable objectAtIndex:indexPath.section] objectForKey:kViewLabel] objectAtIndex:0] ;
        [cell.contentView addSubview:cellValueL];
    }

    if (indexPath.section==1 && indexPath.row==2) {
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    }

    return cell;
}

So far also works ok.

The problem is that when I go back to the previous view and select another option to populate the table, when it’s pushed again, I see the disclosure indicator and blue selection background on other rows on the same section. I’ve observed that it depends on where the table is scrolled.

I’ve tried to understand why does it happen, but i can’t. I’ve somehow solved the problem by setting newView to nil and releasing it and then allocating it again before it gets pushed again.

Am I doing something wrong here? or why is the disclosure indicator and tapping background appearing where they are not supposed to be?

Thanks in advance!

action of the switch

-(void)extraOptionsSwitchAction:(id)sender{



 switch(extraOptionsSwitch.isOn) {

 case 1:

 // [self.tableView beginUpdates];
 [self.tableView insertSections: [NSIndexSet indexSetWithIndex:1]  withRowAnimation:UITableViewRowAnimationAutomatic];
 [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];

 //[self.tableView reloadData];
 //  [self.tableView endUpdates];

 break;

 case !1:

 //   [self.tableView beginUpdates];
 [self.tableView deleteSections: [NSIndexSet indexSetWithIndex:1]  withRowAnimation:UITableViewRowAnimationAutomatic];
 // [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];

 [self.tableView reloadData];
 // [self.tableView endUpdates];

 break;

 }
 }
  • 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-27T05:54:46+00:00Added an answer on May 27, 2026 at 5:54 am

    It has to to with reusing cells. You probably don’t differentiate between the different cell types in your cell creation method – so one cell that went offscreen can easily be reused for another (different type) cell. Further, you seem to add subviews over and over again – only do that when you instantiate the cell (with alloc/int), and not when configuring.

    Also, for different cell types, use different identifiers (you didn’t show this code).

    The programming guides have good example on table views and their cells and reuse pattern. It’s worth reading a couple of times – it’s easy to get wrong and is a main topic for performance tuning.

    Edit

    Now that you added more code, another problem seems to be here:

    if (indexPath.section==1 && indexPath.row==2) {
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    }
    

    You are missing an else part. The selectionStyle and accessoryType are set to what they were set to before – you miss to configure the cells correctly for all other cells than that special one.

    Each cell type should really get its own identifier though. If the adding/removing of subviews work as expected is hard to tell from that code.

    One thought: As you aren’t really reusing a lot of the cells here anyhow you could even disable the reuse by changing

    static NSString *kDisplayCell_ID = @"DisplayCellID";
    cell = [tableView dequeueReusableCellWithIdentifier:kDisplayCell_ID];
    

    to

    static NSString *kDisplayCell_ID = nil;
    

    This would just always produce a new cell. I wouldn’t recommend this in the general case, though.

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

Sidebar

Related Questions

I have a UITableView (on a UIViewController) on which I want to ad an
I have a UITableView which is populated by an array, I have a button
I have a UITableView , which I am controlling from a custom UIViewController .
in app i have custom tableview(UITableView *tableView) which subclass of uiviewcontroller & in tableview
I have a table view which presents a UIViewController whenever a row is tapped
I have put an UITableView inside a UIViewController and have copied code from UITableViewController
I have a UIViewController named RootViewController which contains a UITableView and a UITabBar (2
I have a UIViewController . Within that is a UITableView which is drawn at
I have a UIViewController which uses the UITableViewDelegate and UITableViewDataSource. I have created UITableView
I have an UIViewController which contains a UITableView (subclassed) and another UIView (subclassed). They

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.