The app I'm creating launches with a table view. I can immediately add a new information, save the information to a plist, and reload the view. The new cell and its data shows up at the bottom. When I re-run the app however, it re-orders the order I originally saw them.
The titles of the cell are stored in a variable called countdowns
and the descriptions are stored in countdown_info
. I then use these variables and store them as a dictionary in the plist.
Here's an example that has the same result every time. The following is the table view as it would appear if I had just added 4 new cells:
**[CODE 1]**
Countdown 1
Description 1
Countdown 2
Description 2
Countdown 3
Description 3
Countdown 4
Description 4
However, when the app re-runs/re-builds, the app opens to this:
**[View After Re-Run]**
Countdown 4
Description 4
Countdown 1
Description 1
Countdown 3
Description 3
Countdown 2
Description 2
Some NSLogs I've added reveal the table from the file are saved as [Code 1], and that indexPath.row on the table view increase from 0-3, but for some reason, the view reorganizes with a different pattern.
What is the cause of this? Thanks!
Code from cellRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"] autorelease];
}
ClockworkAppDelegate *dataCenter = (ClockworkAppDelegate *)[[UIApplication sharedApplication] delegate];
cell.textLabel.text = [[dataCenter countdowns] objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [[dataCenter countdown_info] objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}