我在表格视图中有 2 个部分,我从一个数组加载了一个部分,从另一个加载了一个部分。如何设置两个部分的单元格值?
我正在使用以下代码:
标题部分的标题。
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section
{
if(section == 0)
return @" Scheduled Patients ";
else
return @" Walk In Patients ";
}
部分中的行:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section==0)
return [resultArray count];
else {
EMRAppDelegate *appDelegate = (EMRAppDelegate *)[[UIApplication sharedApplication] delegate];
return [appDelegate.walkPatients count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIButton * uploadButton = nil;
static NSString * Identifier = @"Identifier";
UITableViewCell * cell = [table dequeueReusableCellWithIdentifier:Identifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Identifier] autorelease];
uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
[uploadButton setFrame:CGRectMake(10, 10, 24, 24)];
[uploadButton setImage:[UIImage imageNamed:@"upload.png"] forState:UIControlStateNormal];
[uploadButton addTarget:self action:@selector(onUploadButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[uploadButton setTag:999];
cell.accessoryView = uploadButton;
}
else {
uploadButton = (UIButton *)cell.accessoryView;
}
EMRAppDelegate *appDelegate = (EMRAppDelegate *)[[UIApplication sharedApplication] delegate];
ObjectData *theCellData =[resultArray objectAtIndex:indexPath.row];
WalkPatient * patient = [ appDelegate.walkPatients objectAtIndex:indexPath.row];
if (indexPath.section == 0)
{
// do coding for cell loading for Scheduled Patients
cell.textLabel.font = [UIFont systemFontOfSize:18];
cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", theCellData.firstName, theCellData.lasttName];
if (patient.syncDate != nil) {
UIImageView * checkmark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];
[checkmark setFrame:CGRectMake(12, 0, 12, 12)];
[checkmark setTag:998];
[uploadButton addSubview:checkmark];
[checkmark release];
[uploadButton removeTarget:self action:@selector(onUploadButtonClick:) forControlEvents:UIControlEventTouchUpInside];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm"];
cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Synched: %@", [dateFormatter stringFromDate:patient.syncDate]];
[dateFormatter release];
}
else {
UIView * checkmark = (UIView *)[uploadButton viewWithTag:998];
if (checkmark != nil) {
[checkmark removeFromSuperview];
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
else
{
// do load cells for Walk In Patients.
cell.textLabel.font = [UIFont systemFontOfSize:18];
cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", patient.firstName, patient.lastName];
if (patient.syncDate != nil) {
UIImageView * checkmark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];
[checkmark setFrame:CGRectMake(12, 0, 12, 12)];
[checkmark setTag:998];
[uploadButton addSubview:checkmark];
[checkmark release];
[uploadButton removeTarget:self action:@selector(onUploadButtonClick:) forControlEvents:UIControlEventTouchUpInside];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm"];
cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Synched: %@", [dateFormatter stringFromDate:patient.syncDate]];
[dateFormatter release];
}
else {
UIView * checkmark = (UIView *)[uploadButton viewWithTag:998];
if (checkmark != nil) {
[checkmark removeFromSuperview];
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
}