English 中文(简体)
UITableViewCell 动态高度
原标题:Dynamic Height of UITableViewCell

Okay..so before you mark this is as a repeated question, read it. I ve implemented the code given by CIMGF for dynamic resizing of UITableViewCell. It worked for the first time around but does not seem to work now. Strange, right? Anyway, here are the code snippets:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    NSString *text = [[buzzList objectAtIndex:[indexPath row]] objectForKey:@"description"];
    CGSize constraint = CGSizeMake(260, 20000.0f);
    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
    CGFloat height = size.height;

    return height +25 +(CELL_CONTENT_MARGIN * 2);
}

CellForRowAtIndexPath 的相应代码是:

[cell.descriptionLabel setLineBreakMode:UILineBreakModeWordWrap];
[cell.descriptionLabel setMinimumFontSize:FONT_SIZE];
[cell.descriptionLabel setNumberOfLines:0];
[cell.descriptionLabel setFont:[UIFont systemFontOfSize:FONT_SIZE]];

CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);

CGSize size = [[[buzzList objectAtIndex:indexPath.row] objectForKey:@"description"] sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
cell.descriptionLabel.text=[[buzzList objectAtIndex:indexPath.row] objectForKey:@"description"];
CGRect rect=CGRectMake(45, 20, 260, size.height);
[cell.descriptionLabel setFrame:rect];

值 45,20,260 由我设定,以获取单元格中文本的起始点和宽度的确切位置。 值是正确的, 无需修改。 但是, 我执行代码时, 我能得到单元格的正确高度( 根据文本可同步调整) BUT descriptionLabel 显示最多2行文本。 它在此之后截断文本 。 () :

最佳回答

您对描述标签的限制包含两个常数 CELL_conTENT_WIDTH >CELL_conTENT_MARGIN , 而您正在创建的 CGRICT 包含一个数字(260) 如果 CELL_conTENT_WIDTH - (CELL_conTENT_MARGIN *2) & gt; 260, 那么这应该是你的问题。

问题回答

暂无回答




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签