tags:

views:

103

answers:

2

I'm working on upgrading my app to 3.0, and a new bug has developed that didn't exist in 2.2.1 (in fact this is the only problem I had by upgrading... other than a setText: is depreciated warning)

I have a tableView with cells which have switch controls on them. With the viewWillAppear, I am setting these switches based of values read from a plist file.

Problem: now that I've converted to 3.0 I have to use the tabBar to go back and forth between this tableView and any of the other views two times before it will set the switch values. Using the debugger the first time and the second time I have verified it goes through the "refreshSwitches" function both times.... i.e. there isn't a difference in how it goes through the code/functions... on the first, second, or anytime therebafter.

The values are read from the plist correctly, but all the switches are off...on the first time the view appears?? Any ideas.

A: 

for some reason after I registered it won't let me edit my question, I apologize for posting the code seperate... here is the code that worked in 2.2.1, but doesn't in 3.0. Note: I threw in an AlertView for debugging (as well as using the normal debugging tools)...

the first time I go to the view I get on the AlertView:

1 IS NOT on

the second (and any remaining times) I go to the view I get on the AlertView:

1 IS on

// I've Tried viewDid and Will Appear, both have the same result. - (void)viewDidAppear:(BOOL)animated { [self refreshView]; }

  • (void)refreshView{ UITableViewCell *cell; UISwitch *switchView; NSIndexPath *indexPath;

    indexPath = [NSIndexPath indexPathForRow:0 inSection:1]; cell = [thisTableView cellForRowAtIndexPath:indexPath]; switchView = (UISwitch *)[cell viewWithTag:kSwitchTag]; switchView.on = ([SharedClass sharedSharedClass].tempVar == 1) ? YES : NO;

    NSString *baseString = @"%u %@."; NSString *onString = (switchView.on) ? @"IS on" : @"IS NOT on"; NSString *messageString = [[NSString alloc] initWithFormat:baseString, [SharedClass sharedSharedClass].tempVar, onString];

    // TEMP DEBUG ALERTVIEW

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"INDICATOR Row Selected" message:messageString delegate:nil cancelButtonTitle:@"Thanks" otherButtonTitles:nil];

[alert show]; [alert release]; [messageString release];

[self.thisTableView reloadData];

}

driveguy
I know the code I pasted didn't paste very well, I tried to clean it up, but couldn't get it to display. To answer the question about the cell... I'm not "passing" a cell to the method, I'm setting the indexPath and creating a pointer to the cell so I have access to the switch control on the cell. So no I don't think that it would be set to nil anywhere.I would think the cell and the tableView exists since I'm not trying to make the pointer to the cell until viewWill or viewDid Appear
driveguy
A: 

Are you sure the cell passed in to this method is ever nil? That would account for why the value is off, after you set it to on...

Kendall Helmstetter Gelner