如何在主-详细视图类型应用程序中重置详细视图?例如,我的主视图仅列出姓名,当您选择姓名时,我想要您选择的那个人的详细信息。应用程序将执行的操作。但是,当我从详细视图中按下“返回”按钮并选择另一个名称时,详细视图将保留第一个选定的项目。如何重置该详细信息视图,以便显示所选内容的详细信息?
我的 detailviewcontroller 中有这个(Profile 是一个类):
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil title:(NSString *)name details:(Profile *)profile{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Detail", @"Detail");
NSLog(@"Details: %@", [profile lastName]);
_detailProfile = profile;
}
return self;
}
这是在我的主视图控制器中:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.detailViewController) {
//self.detailViewController = [[MediaDirectoryDetailViewController alloc] initWithNibName:@"MediaDirectoryDetailViewController" bundle:nil];
_showProfile = [_profileArray objectAtIndex:indexPath.row];
self.detailViewController = [[MediaDirectoryDetailViewController alloc] initWithNibName:@"MediaDirectoryDetailViewController" bundle:nil title:@"Detail" details:_showProfile];
}
NSDate *object = _objects[indexPath.row];
self.detailViewController.detailItem = object;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
根据收到的答案编辑
行。detailProfile 是详细视图控制器的属性,我创建了一个方法:
@property (strong, nonatomic) Profile *detailProfile;
-(void)setDetailProfile:(Profile *)profile;
实现如下:
-(void)setDetailProfile:(Profile *)profile{
NSLog(@"Going to display profile: %@, %@", [profile lastName], [profile firstName]);
[firstName setText:[profile firstName]];
[lastName setText:[profile lastName]];
}
现在,无论出于何种原因,我的标签 firstName 和 lastName 都没有更新。
我在主人身上做了以下事情:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.detailViewController) {
//self.detailViewController = [[MediaDirectoryDetailViewController alloc] initWithNibName:@"MediaDirectoryDetailViewController" bundle:nil];
_showProfile = [_profileArray objectAtIndex:indexPath.row];
NSLog(@"Profile selected last name: %@", [_showProfile lastName]);
// self.detailViewController = [[MediaDirectoryDetailViewController alloc] initWithNibName:@"MediaDirectoryDetailViewController" bundle:nil title:@"Detail" details:_showProfile];
self.detailViewController = [[MediaDirectoryDetailViewController alloc] initWithNibName:@"MediaDirectoryDetailViewController" bundle:nil title:@"Detail"];
self.detailViewController.detailProfile = _showProfile;
}
NSDate *object = _objects[indexPath.row];
self.detailViewController.detailItem = object;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
我对日志的输出选择新项目时不会更新 - 从详细信息返回后 - 我的标签正在更新。