gpt4 book ai didi

objective-c - 在我按返回键并选择另一个选项后,表格没有刷新。始终与第一个选择相同的表

转载 作者:行者123 更新时间:2023-11-28 20:45:56 24 4
gpt4 key购买 nike

我的主页中有一个 Patient 对象列表,它是一个表格 View 。当我单击其中一行时,它将转到另一个页面,该页面显示与该特定患者相关的两个选项,选项 1 是“患者信息”,选项 2 是所选特定患者的所有入院日期的列表。

我在使用第二个选项时遇到了一些问题——当我返回主页并选择另一个患者时,入院日期表似乎没有刷新。入院日期表始终显示我选择的第一个患者的入院日期。真不知道哪里错了。

我使用了viewWillAppear方法,因为viewDidLoad好像只调用了一次;我证明了使用 NSLog(_nric); - 它只打印一次。我怀疑是表格 View 方法给我带来了问题。有人可以就下面的第二种方法给我一些建议吗?

- (void)viewWillAppear:(BOOL)animated {
_listOfPatientsAdmInfoOptions = [[NSMutableArray alloc] init];



for(PatientAdmInfo *patientAdmInfo1 in [[PatientDatabase database] patientAdminList:_nric]){

[ _listOfPatientsAdmInfoOptions addObject:patientAdmInfo1];
NSLog(_nric);

}
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...

_patientAdmInfo = [[PatientAdmInfo alloc] init ];


_patientAdmInfo = [_listOfPatientsAdmInfoOptions objectAtIndex:indexPath.row];

cell.textLabel.text = _patientAdmInfo.pDiagnosis;
//cell.detailTextLabel.text = patientAdmInfo.pDiagnosis, patientAdmInfo.sDiagnosis;


return cell;
}

最佳答案

(void)viewWillAppear: 中更新数组后,调用表实例上的 reloadData 方法。

[myTabelView reloadData];

并且不要忘记在 viewWillAppear 方法中调用 [super viewWillAppear:animated];

所以你的 viewWillAppear 方法应该是..

-

(void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];
_listOfPatientsAdmInfoOptions = [[NSMutableArray alloc] init];



for(PatientAdmInfo *patientAdmInfo1 in [[PatientDatabase database] patientAdminList:_nric]){

[ _listOfPatientsAdmInfoOptions addObject:patientAdmInfo1];
NSLog(_nric);

}
[myTabelView reloadData];
}

关于objective-c - 在我按返回键并选择另一个选项后,表格没有刷新。始终与第一个选择相同的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6403286/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com