gpt4 book ai didi

iphone - 当我为 UITableView 设置 rowHeight 时,单元格的高度不应该也改变吗?

转载 作者:可可西里 更新时间:2023-11-01 05:38:39 25 4
gpt4 key购买 nike

问题:
当我为 UITableView 设置 rowHeight 时,单元格的高度不应该也改变吗?
以下是让我思考的情况:


我想为底部的每个表格 View 单元格设置一个单独的行,而且我想为它设置行高从4432。我想要的结果如下:

行高设置正确:

- (void)viewDidLoad
{
[super viewDidLoad];

[self.tableView setRowHeight:32.0f];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

//...
}

// Even use the delegate of UITableView
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 32.0f;
}

但是,当我为单元格添加单独的行时,我遇到了一个问题:我想在单元格的底部设置单独的行,所以我通过 cell 设置了 y 的位置.frame.size.height - 1.0f。不幸的是,结果如下:

当我选择时,单元格发生如下变化:

1。选中第 1 行:

2。选中第2行:

3。选中第 3 行:

好像选中前cell的高度是44,选中后变成了32。像卡片一样一张一张重叠的对不对?奇怪!

主要代码:

- (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];
[cell.textLabel setFont:[UIFont fontWithName:@"Futura-Medium" size:15.0f]];
UIView * seperateLine = [[UIView alloc] initWithFrame:CGRectMake(10.0f, cell.frame.size.height - 1.0f, 300.0f, 1.0f)];
NSLog(@">>>>>>>>>>>>>>>> %f", cell.frame.size.height);
[seperateLine setBackgroundColor:[UIColor grayColor]];
[cell.contentView addSubview:seperateLine];
[seperateLine release];
}

//...
}

我试着查看cell.frame.size.height,最后是44。然后,我替换行

UIView * seperateLine = [[UIView alloc] initWithFrame:CGRectMake(10.0f, cell.frame.size.height - 1.0f, 300.0f, 1.0f)];

UIView * seperateLine = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 31.0f, 300.0f, 1.0f)];

它作为上面显示的第一张图片。但是单元格的高度仍然是 44,它们(我们完全看不到)仍然重叠。我所做的只是在 y 位置是 32 但它的总高度是 44 的地方添加了一个 separate line .


那么您对此有何看法? :?

最佳答案

问题:

根据苹果的 HIG,默认的可点击区域是 44,所以默认情况下所有控件的高度都是 44。

你在里面定义了新的UITableViewCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

默认情况下为 44,您在 UITableViewCell 的框架中不做任何更改并返回它。

解决方案:

尝试设置 UITableViewCell 的框架大小,即 cell.frame = CGRectMake(0.0f, 0.0f, 320.0f, 32.0f)

关于iphone - 当我为 UITableView 设置 rowHeight 时,单元格的高度不应该也改变吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8489876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com