0

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

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

我使用该viewWillAppear方法是因为viewDidLoad似乎只被调用一次;我证明了使用NSLog(_nric);-- 它只打印一次。我怀疑这是给我问题的表格视图方法。有人可以就下面的第二种方法给我一些建议吗?

- (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;
}
4

2 回答 2

3

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

[myTabelView reloadData];

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

所以你的 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];
}
于 2011-06-19T15:38:47.713 回答
0

这是因为您的_patientAdmInfo对象是一个实例变量。表格中的每个单元格都在查看同一个对象以获取其数据。您的cellForRowAtIndexPath:方法应如下所示:

PatientAdminInfo *tempPatient = [_listOfPatientsAdmInfoOptions objectAtIndex:indexPath.row];
cell.textLabel.text = tempPatient.pDiagnosis;

这将确保每个单元格都在查看适当的 PatientAdminInfo 对象。

于 2011-06-19T16:01:08.377 回答