多个阵列名称在一个地方

时间:2013-07-10 13:39:41

标签: iphone ios uitableview nsmutablearray

我有一个存储应用程序,您可以分别输入名字和姓氏,我想知道是否可以将名称放在同一个tableView项目中。

这是我的tableView代码:

#pragma mark UITableViewDataSource Methods

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"cell"];
    if ( nil == cell ) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }

    NSLog(@"indexPath.row = %d, patients.count = %d", indexPath.row, patients.count);
    Patient *thisPatient = [patients objectAtIndex:indexPath.row];
    cell.textLabel.text = thisPatient.patientName;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.textColor = [UIColor blackColor];
    if (self.editing) {
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
                        return [patients count];
}

#pragma mark UITableViewDelegate Methods

- (void) tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ( editingStyle == UITableViewCellEditingStyleDelete ) {
        [patients removeObjectAtIndex:indexPath.row];
        [tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
    }
}

- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    LSAppDelegate *delegate = (LSAppDelegate *)[[UIApplication sharedApplication] delegate];
    PatientController *patient = [[PatientController alloc] initWithIndexPath:indexPath];
    [delegate.navController pushViewController:patient animated:YES];
    [tv deselectRowAtIndexPath:indexPath animated:YES];
}

我尝试了cell.textLabel.text = thisPatient.patientName, thisPatient.patientSurname;

虽然它只显示名字,但它应显示名字和姓氏 提前致谢

3 个答案:

答案 0 :(得分:0)

当然有可能。您需要创建自己的UITableViewCell,因此您可以将两个字段显示在同一个单元格中。看看这个tutorial,它可以满足您的需求。

答案 1 :(得分:0)

将我的评论带到anwser:

使用

cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", thisPatient.patientName, thisPatient.patientSurname];

或您喜欢的自定义格式。

也可能:

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];

-

cell.textLabel.text = thisPatient.patientName;
cell.detailTextLabel.text = thisPatient.patientSurname;

答案 2 :(得分:0)

您还可以创建具有两个单独标签的自定义单元格。这具有将标签放置在彼此之上或以任何其他布置放置的优点。您还可以使用免费Sensible TableView等框架自动为您填写这些标签。

相关问题