iphone - 增加 tableView 单元格的大小?

标签 iphone ios uiview label tableview

我有一个带有自定义单元格的 tableView,它由 3 个标签、名称、书籍和章节组成。不幸的是,我的单元格似乎不够大,无法容纳 3 个标签,我想把它变大。我应该在下面的代码中做什么才能以最佳方式实现这一目标?/问候

tableView 中单元格的图片:http://tinypic.com/view.php?pic=2vrzpu9&s=6

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"BookmarkCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Bookmark *item = [self.items objectAtIndex:indexPath.row];

NSArray *chunks = [item.name componentsSeparatedByString: @","];

NSString *name;
NSString *book;
NSString *chapter;

if ([chunks count] > 0)
{
    name = [chunks objectAtIndex:0];
    if ([chunks count] > 1)
    {
        book = [chunks objectAtIndex:1];
        if ([chunks count] > 2)
        {
            chapter = [chunks objectAtIndex:2];
        }
    }
}

UIView * pNewContentView= [[UIView alloc] initWithFrame:cell.contentView.bounds];
CGRect labelFrame= pNewContentView.bounds;
labelFrame.size.height= labelFrame.size.height * 0.25;

UILabel* pLabel1=[[UILabel alloc] initWithFrame:labelFrame];
[pNewContentView addSubview:pLabel1];

labelFrame.origin.y= labelFrame.size.height;
UILabel* pLabel2=[[UILabel alloc] initWithFrame:labelFrame];
[pNewContentView addSubview:pLabel2];

labelFrame.origin.y= labelFrame.origin.y + labelFrame.size.height;
UILabel* pLabel3=[[UILabel alloc] initWithFrame:labelFrame];
[pNewContentView addSubview:pLabel3];

[cell.contentView addSubview:pNewContentView];

[pLabel1 setText:(name)];    
[pLabel2 setText:(book)];  
[pLabel3 setText:(chapter)];       


//cell.textLabel.text = chapter;
//cell.textLabel.text = name;
//cell.detailTextLabel.text = book;


return cell;
}

最佳答案

很容易自定义 UITableViewCell 的高度

只需添加委托(delegate)方法

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    return 70; // or whatever height you need
}

关于iphone - 增加 tableView 单元格的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12165368/

相关文章:

iphone - 从提要中填充 UIPickerView

iphone - 这个要怎么释放呢?

iphone - 从应用内调用并保留应用状态

ios - UIView 和 ScrollView 之间的 UIView 过渡翻转

iphone - 使用 CoreTelephony 获取运营商名称仅返回 "Carrier"

iphone - 如何获取 NSHTTPURLResponse 的状态描述

ios - sgxTextureGetImageRowBytes EXC_BAD_ACCESS

ios - 检测加载方向

ios - touchesMoved 在 CAShapeLayer 中绘制缓慢/滞后

objective-c - animateWithDuration 立即完成