在iOS中使用自定义视图在tableView中显示数据

在iOS中使用自定义视图在tableView中显示数据,ios,objective-c,uitableview,custom-view,Ios,Objective C,Uitableview,Custom View,在我的应用程序中,我有一个tableview,我使用分区而不是按行访问它。 我在剖面上使用了自定义视图,自定义视图包含的标签很少 在我的牢房里 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath { viewOrderPage=[[ViewOrder alloc]init]; static NSString * cellIdentifier=

在我的应用程序中,我有一个tableview,我使用分区而不是按行访问它。
我在剖面上使用了自定义视图,自定义视图包含的标签很少

在我的牢房里

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
viewOrderPage=[[ViewOrder alloc]init];

static NSString * cellIdentifier=@"Mytable";
UITableViewCell * cell;



if(cell==nil)
{
    cell=[contentTable dequeueReusableCellWithIdentifier:cellIdentifier];
    cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    viewOrderPage=[[ViewOrder alloc]initWithFrame:CGRectMake(0, 0, 310, 60)];
    viewOrderPage.tag=111;
    [cell.contentView addSubview:viewOrderPage];

}
else
{
    viewOrderPage=(ViewOrder *)[cell.contentView viewWithTag:111];
}


viewOrderPage.productName.text=@"aaa";

return cell;
}
但该值不会显示在单元格中

viewOrderPage is the object of the customview(ViewOrder) and productName is a label in the view
修改代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellIdentifier=@"Mytable";
    ViewOrder * cell= (ViewOrder *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if(cell==nil)
    {
        [[NSBundle mainBundle] loadNibNamed:@"ViewOrder" owner:self options:nil];
        cell=self.vieworder;
    }

NSString * str=[NSString stringWithFormat:@"%@",[productArray objectAtIndex:indexPath.row]];
NSLog(@"%@",str);

    cell.productName.text=str;


    return cell;
    }

希望它能帮助您..

但是str正在日志中打印您应该创建一个适当的UITableView子项您可以详细说明您可以搜索它吗?被苹果的文档和成千上万的博客帖子和堆栈溢出帖子覆盖。你说,适当的子类,这意味着?一个真正的子类。不是仅更改视图层次结构的UITableViewCell