我有一個表格視圖中的2個部分,我已經從一個數組加載一個部分,另一個從另一個。我如何設置兩個部分的單元格值?如何在表格視圖的兩部分加載數據iPhone
我使用的是以下代碼:
標題部分的標題。
- (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;
}
}
什麼是你的問題? – EightyEight 2012-04-06 05:03:34
問題如何在單元格表視圖中爲兩個部分加載值 – 2012-04-06 05:04:54
+1,因爲在提問之前已經做了一些努力。 – 2012-04-06 05:06:16