Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cnstoll

macrumors 6502
Original poster
Aug 29, 2010
254
0
So..I've managed to rig up a table view cell to display a segmented control. It actually works pretty well. The problem is that if I try to reload anything in the table (even a specific row with reloadRowsAtIndexPaths) the segmented control disappears.

This is how I currently have it set up where in the cellForRowAtIndexPath delegate method:

Code:
// segControl is declared in the header		
segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Option1", @"Option2", nil]];
segControl.frame = CGRectMake(-1.0f, -1.0f, 302.0f, 46.0f);
[segControl addTarget:self action:@selector(segChanged:) forControlEvents:UIControlEventValueChanged];
[cell.contentView addSubview:segControl];

Any ideas why this would be happening or how to fix it? Thanks
 
So, you have one segControl instance for every single row in the table?

Nope. Only for one specific row in one section. It's a settings dialog and most of the rows are different.

I don't have the rest of my code with me, but I just realized something. I think I may be using the same cellIdentifier for all the cells.... I bet using a specific cell identifier for that cell..and maybe all the different types of cells for that matter..will fix the problem.

Thoughts?
 
Last edited:
I figured it out. It's because of where I was calling "reloadRowsAtIndexPaths". I was calling it inside of the selector for changing the segmented control, because I am trying to modify text in a certain cell based on the selected segment.

In the cellForRowAtIndexPath method I set the selected index of the segmented control. That calls the selector, and that fires off the reloadRowsAtIndexPaths...but that happens before the view appears, and apparently that's not good.

Solution? Use a little boolean to see if it's the initial call or not...and if not...then it's safe to reload the rows.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.