Heres my cellForRowAtIndexPath where I've loading a value for a row, instead of a value from a simple array and converting it to a row.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:CellIdentifier] autorelease];
}
NSInteger row = [indexPath row];
cell.textLabel.text = [dayArray objectAtIndex:row];
NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];
NSInteger startRow = [myDefaults integerForKey:kStartRow];
if (startRow == row) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
Heres where I'm saving the value, notice I'm using kStartRow and the array value each time.
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int newRow = [indexPath row];
NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];
[myDefaults setInteger:newRow forKey:kStartRow]; // Set the tablecell
[myDefaults setObject:[dayArray objectAtIndex:newRow] forKey:kNSUEndOfMonthDay];
[myDefaults synchronize];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView reloadData];
[self.navigationController popViewControllerAnimated:YES];
}
Using two values makes is a bit messy now when I want to set a default when the app first runs. How can I manage with one stored value ?