我想你可以使用nsuser默认值。
// view controller to make selection
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selected;
if (indexPath.row == 0) {
selected = @"Apple";
} else if (indexPath.row == 1) {
selected = @"Microsoft";
}
[[NSUserDefaults standardUserDefaults] setObject:selected forKey:@"SELECTED"];
[self.navigationController popViewControllerAnimated:YES];
}
重要的一点是,您需要在viewdidAppear中调用[self.tableview reloaddata]。
// view controller to show what a user selected
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.tableView reloadData];
}
- (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];
}
// Configure the cell.
cell.textLabel.text = @"Choice";
cell.detailTextLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"SELECTED"];
return cell;
}