Okay, so.
I am trying to have a toggle switch, that in a certain state some rows are visible. Some are not.
Here is a VERY basic example, that shows the error.
Create a blank Navigation project, with the TableView.
Change it in IB to a GroupTable, then drop this code in place.
So you can see what I am talking about.
The first section, the first row is set to red text.
The Second section, the first row is set to black. When the app first starts, the toggle switch is off, so there is no second row.
Click on the first row in the second section, and this toggles the switch. Reloads the table, and my second row appears.
However now the FIRST row in the section section, it's text goes to red.
toggle it off, and it goes back to black.
As you can see from the code, the logic of the formating of the cell the color settings are never applied to the cell in the second section.
So any input on if I am coding this right, or is just a bug would greatly appreciated:
I am trying to have a toggle switch, that in a certain state some rows are visible. Some are not.
Here is a VERY basic example, that shows the error.
Create a blank Navigation project, with the TableView.
Change it in IB to a GroupTable, then drop this code in place.
So you can see what I am talking about.
The first section, the first row is set to red text.
The Second section, the first row is set to black. When the app first starts, the toggle switch is off, so there is no second row.
Click on the first row in the second section, and this toggles the switch. Reloads the table, and my second row appears.
However now the FIRST row in the section section, it's text goes to red.
toggle it off, and it goes back to black.
As you can see from the code, the logic of the formating of the cell the color settings are never applied to the cell in the second section.
So any input on if I am coding this right, or is just a bug would greatly appreciated:
Code:
#import "RootViewController.h"
#import "TestingCellBugAppDelegate.h"
@implementation RootViewController
BOOL switchTestState = FALSE;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0)
return 1;
if (section == 1)
if (switchTestState)
return 2;
else
return 1;
return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 0)
return @"Static Section";
if (section == 1)
return @"Dynamic Section";
return nil;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
if (indexPath.section == 0) {
[cell setTextColor:[UIColor redColor]];
[cell setText:@"Static No Change"];
}
if (indexPath.section == 1) {
if (indexPath.row == 0)
[cell setText:@"Toggle Switch"];
if (indexPath.row == 1)
[cell setText:@"Is Turned On/Off"];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ((indexPath.section == 1) && (indexPath.row == 0)) {
if (switchTestState)
switchTestState = FALSE;
else
switchTestState = TRUE;
[[self tableView] reloadData];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)dealloc {
[super dealloc];
}
@end