如何使添加到UITableViewCell内容视图的UIView在其范围之内?

| 如何使添加到UITableViewCell内容视图的UIView在其范围之内? 也就是说,我已经创建了一个NIB文件(上面带有3个标签),并希望将其用于UITableView中每个单元的显示。我在cellForRowAtIndexPath方法中添加了基于自定义NIB的视图到单元格的内容视图,但是最终我看到的只是一(1)个基于自定义NIB的视图(在表视图中没有像我预期的那样多个) 。 我该如何安排,使每个自定义视图都可以恰好适合每个UITableViewCell?另请注意,自定义NIB视图中的标签具有自动换行功能。 我是否必须为自定义NIB视图创建框架,但是在那种情况下,我不确定如何设置坐标。相对于UITableViewCell吗?并且如果自定义视图的高度可以由于UILabel的自动换行而改变,那么我假设我必须分别在UITableView中手动计算该高度? (也许我应该去创建动态/自定义视图,并放弃使用InterfaceBuilder / NIB的概念)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @\"Cell\";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    UIView *detailedView = [[[NSBundle mainBundle] loadNibNamed:@\"DetailedAppointView\" owner:self options:nil] objectAtIndex:0];
    [cell.contentView addSubview:detailedView];  // DOESN\'T SEE TO WORK

    return cell;
}
    
已邀请:
        如果需要实现自定义UITableViewCell,这就是我的方法。 我为自定义单元格ex创建一个create1ѭ的子类。 \“ MyCustomCell \”。然后,我为此创建一个NIB文件,并在此NIB文件中插入
UITableViewCell
并将其类型更改为\“ MyCustomCell \”,并为其指定一个与类名相同的标识符。然后,将所有子视图插入到单元格中。全部在IB中。 在我将自己的单元格整理好之后:-)我以以下方式使用它:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @\"MyCustomCell\";
    static NSString *CellNib = @\"MyCustomCell\";

    MyCustomCell *cell = (MyCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
        cell = (MyCustomCell *)[nib objectAtIndex:0];
    }

    //Manipulate your custom cell here

    return cell;
}
    

要回复问题请先登录注册