我按后退并选择另一个选项后,表格不会刷新。始终与第一个选择相同的表
我的主页中有一个 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;
}
I have a list of Patient
objects in my main page, which is a table view. When I click on one of the rows, it will go to another page which shows two options pertaining to that particular patient, option 1 being "Patient Info", and option 2 being a list of all admission dates of the particular patient selected.
I have some trouble with the second option -- the table of admission dates does not seem to refresh when I return back to the main page and select another patient. The admission dates table always shows the the admission dates of the first patient which I have selected. I really do not know where is the mistake.
I used the viewWillAppear
method because viewDidLoad
seems to only be called once; I proved that using NSLog(_nric);
-- it only prints once. I suspect it's the table view method which is giving me the problem. Can someone please give me some advice on my second method below?
- (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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 -
(void)viewWillAppear:
中更新数组后,在表实例上调用reloadData
方法。并且不要忘记在
viewWillAppear
方法中调用[super viewWillAppear:animated];
。所以你的 viewWillAppear 方法应该是..
-
Call
reloadData
method on your table Instance after updating your array in -(void)viewWillAppear:
.And also not forget to call
[super viewWillAppear:animated];
inviewWillAppear
method.So your viewWillAppear method should be ..
-
这是因为您的
_patentAdmInfo
对象是一个实例变量。表中的每个单元格都在查看同一对象以获取其数据。您的cellForRowAtIndexPath:
方法应如下所示:这将确保每个单元格都在查看适当的 PatientAdminInfo 对象。
It's because your
_patientAdmInfo
object is an instance variable. Every cell in your table is looking at the same object to get its data. YourcellForRowAtIndexPath:
method should look like this:this will ensure that every cell is looking at the appropriate PatientAdminInfo object.