iOS表视图换行重叠

iOS表视图换行重叠,ios,json,uitableview,word-wrap,Ios,Json,Uitableview,Word Wrap,我使用JSON解析到一个表视图。我用的是标题和副标题。我不希望文本在屏幕上出现“…”字样,所以我加了一句 cell.textLabel.numberOfLines = 0; cell.detailTextLabel.numberOfLines = 0; 我可以看到它进入了一条新的线,但细胞的高度保持不变,与其他细胞重叠,看起来非常糟糕。我怎样才能使它的文字包装和高度扩展的内容量呢 提前谢谢 第一个答案的答案:我输入UITableViewDelegate方法的代码,得到如下结果: 2013-08

我使用JSON解析到一个表视图。我用的是标题和副标题。我不希望文本在屏幕上出现“…”字样,所以我加了一句

cell.textLabel.numberOfLines = 0;
cell.detailTextLabel.numberOfLines = 0;
我可以看到它进入了一条新的线,但细胞的高度保持不变,与其他细胞重叠,看起来非常糟糕。我怎样才能使它的文字包装和高度扩展的内容量呢

提前谢谢

第一个答案的答案:我输入UITableViewDelegate方法的代码,得到如下结果:

2013-08-27 15:29:40.940 jsonParse[2392:c07] -[__NSCFDictionary 

sizeWithFont:constrainedToSize:lineBreakMode:]: unrecognized selector sent to instance 0x7580130
2013-08-27 15:29:40.942 jsonParse[2392:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary sizeWithFont:constrainedToSize:lineBreakMode:]: unrecognized selector sent to instance 0x7580130'
*** First throw call stack:
(0x1c93012 0x10d0e7e 0x1d1e4bd 0x1c82bbc 0x1c8294e 0x333a 0x1f9c4e 0x1fc224 0xc0952 0xc02dc 0x2927 0xbd6589 0xbd4652 0xbd589a 0xbd460d 0xbd4785 0xb21a68 0x4615911 0x4614bb3 0x4652cda 0x1c358fd 0x465335c 0x46532d5 0x453d250 0x1c16f3f 0x1c1696f 0x1c39734 0x1c38f44 0x1c38e1b 0x1bed7e3 0x1bed668 0x14ffc 0x1dad 0x1cd5 0x1)
libc++abi.dylib: terminate called throwing an exception

实现此UITableViewDelegate方法以在运行时查找每行的高度,并相应地更改代码

    NSString *object = [DataArray objectAtIndex:indexPath.row];
    CGSize size = [object sizeWithFont:[UIFont systemFontOfSize:[UIFont systemFontSize]] constrainedToSize:CGSizeMake(300, 9999) lineBreakMode:NSLineBreakByWordWrapping];//set the textLable Frame width according to your layout width.
    CGFloat height = size.height+20;//you can set the padding accordingly
    return height;
}
针对具体答案进行编辑

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *title = [[articles objectAtIndex:indexPath.row] objectForKey:@"title"];
    NSString *desc = [[articles objectAtIndex:indexPath.row] objectForKey:@"desc"];

    CGSize titleSize = [title sizeWithFont:[UIFont boldSystemFontOfSize:18.0] constrainedToSize:CGSizeMake(300, 99999) lineBreakMode:NSLineBreakByWordWrapping];
    CGSize descSize = [title sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:CGSizeMake(300, 99999) lineBreakMode:NSLineBreakByWordWrapping];
    return titleSize.height+descSize.height+10;
}

您已在NSString对象中传递dictionary对象。您已经获得了在textLabel.text中设置的NSString对象,还粘贴了此方法的-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath的代码。虽然删除了错误,但看起来仍然一样,是否需要调用此方法?否,它将根据tableview委派的属性自动调用。确保正确设置了tableview.gelegate=self;我把tableView.delegate=self放在哪里?你解决了你的问题了吗?如果没有,请告诉我…只是看了你的屏幕截图,发现了问题