UITableViewCell 子类未显示正确的大小
我有一个我制作的 UITableViewCell 子类的 nib 文件,它的高度在 nib 中设置为 25,但是当应用程序加载时,情况并非如此。它加载到默认大小。这是我的单元实现代码。
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
//cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell = choreCell;
}
return cell;
}
我尝试使用 cell.frame = CGRectMake(0, 0, 320, 25)
设置框架,但它不起作用。有什么想法吗?
I have a nib file for a UITableViewCell subclass I made, it's height is set to 25 in the nib, however when the application loads, this is not the case. It loads to the default size. Here is my code for the implementation of the cell.
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
//cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell = choreCell;
}
return cell;
}
I've tried setting the frame with cell.frame = CGRectMake(0, 0, 320, 25)
however it didn't work. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
单元格高度在表格视图委托的
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
方法中指定。The cell height is specified in the
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
method of your table view's delegate.