Ios 是否以特定格式显示表视图数据?

Ios 是否以特定格式显示表视图数据?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,在我的表视图中,我想在ios中显示一些标题,那么我可以做些什么来实现这一点。下面给出了我的代码…因为我想显示如下的数据。。。。。 名称类没有地址 在“表视图”中,然后执行此操作。。有人能帮我吗 enter code here deliveryCases = [[UITableView alloc]initWithFrame:CGRectMake(20, 20, 320, 480)]; deliveryCases.backgroundColor = [UIColor clearC

在我的表视图中,我想在ios中显示一些标题,那么我可以做些什么来实现这一点。下面给出了我的代码…因为我想显示如下的数据。。。。。 名称类没有地址 在“表视图”中,然后执行此操作。。有人能帮我吗

enter code here
    deliveryCases = [[UITableView alloc]initWithFrame:CGRectMake(20, 20, 320, 480)];
     deliveryCases.backgroundColor = [UIColor clearColor];
     deliveryCases.dataSource = self;
     deliveryCases.delegate = self;
    [self.view addSubview:deliveryCases];

  UIView *headerView0 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100 , 50)];
     UILabel *labelView0 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100 , 50)];
    labelView0.text = @"Name";
  [headerView0 addSubview:labelView0];
  deliveryCases.tableHeaderView = headerView0;


    UIView *headerView1 = [[UIView alloc] initWithFrame:CGRectMake(10, 19, 100 , 50)];
   UILabel *labelView1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 19, 100 , 50)];
 labelView1.text = @"CLass";
  [headerView1 addSubview:labelView1];
 deliveryCases.tableHeaderView = headerView1;
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *cellIdentifier = @"CellIdentifier";
   UITableViewCell *cell = [deliveryCases     dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil)
{
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

}

      [cell setUserInteractionEnabled:YES];
     tableView.allowsSelection=YES;

       return cell;



  }

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
 {
    return 1;
  }   

    -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
     return 2;
}

您所做的是正确的,在标题中添加了一个视图。有了所有标签的正确原点,您将实现您想要的

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UIView *headerView = [[UIView alloc] initWithFrame:VIEW_FRAME_HERE];


    UILabel *lbl1 = [[UILabel alloc] initWithFrame:LABEL_FRAME_HERE];
    lbl1.text = @"YOUR_HEADER_NAME";
    [headerView addSubview:lbl1];

    UILabel *lbl2 = [[UILabel alloc] initWithFrame:LABEL_FRAME_HERE];
    lbl2.text = @"YOUR_HEADER_NAME";
    [headerView addSubview:lbl2];
    .
    .
    .
    return headerView;
}
因此,在TableViewCell中,只需向其中添加一个子视图,其中包含正确的标签原点及其值。如果您将UITableViewCell子类化并在其中添加子视图,这将是合适的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *myCell = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myCell];
    if(!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myCell];
    }

    UIView *cellValues = [[UIView alloc] initWithFrame:CELL_FRAME_HERE];


    UILabel *value1 = [[UILabel alloc] initWithFrame:VALUE_FRAME_HERE];
    value1.text = @"VALUES_HERE";
    [cellValues addSubview:value1];

    UILabel *value2 = [[UILabel alloc] initWithFrame:VALUE_FRAME_HERE];
    value2.text = @"VALUES_HERE";
    [cellValues addSubview:value2];
    .
    .
    .
    [cell addSubview:cellValues];
    return cell;
}

是的,就像在单元格中添加标签一样,只需在单元格中添加UITextField。。。如果你想确定一个特定的字段,把标签放在你的字段中,并通过标签访问它们