Uitableview 自定义单元自定义uitableveiwcell带IB
我尝试创建自定义uitableviewcell,我使用IB创建自定义单元格,我放置单元格的类,连接IB,然后我以以下方式使用单元格:Uitableview 自定义单元自定义uitableveiwcell带IB,uitableview,uitextview,Uitableview,Uitextview,我尝试创建自定义uitableviewcell,我使用IB创建自定义单元格,我放置单元格的类,连接IB,然后我以以下方式使用单元格: - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Identifie
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Identifier"];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
if (indexPath.row == 0) {
[cell.username setText:@"Load more"];
[cell.testo setText:@""];
}
else {
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
PFObject *obj = [self.arrayMessaggi objectAtIndex:indexPath.row - 1];
PFUser *user = [obj objectForKey:@"daUtente"];
float height = [self getStringHeight:[obj objectForKey:@"TestoMessaggio"]
andFont:[UIFont italicSystemFontOfSize:13]];
NSLog(@"Height: %f",height);
[cell.username setFrame:CGRectMake(10, 5, 300, 20)];
[cell.username setText:[user objectForKey:@"username"]];
[cell.testo setFrame:CGRectMake(10, 25, 300, height)];
[cell.testo setText:[obj objectForKey:@"TestoMessaggio"]];
}
return cell;
}
问题是textview的高度是错误的,高度值是正确的,但是textview的帧比较小,然后如果我上下滚动textview的帧,它会变为IB的大小。我希望它能帮助你
NSString *someText = [NSString stringWithFormat:@"%@",[obj objectForKey:@"TestoMessaggio"]];
CGSize constraintSize;
constraintSize.width = 300.0f;
constraintSize.height =100000;
CGSize stringSize =[someText sizeWithFont: [UIFont boldSystemFontOfSize: 17] constrainedToSize: constraintSize lineBreakMode: UILineBreakModeWordWrap];
CGRect rect ;
if (stringSize.height>37) {
rect = CGRectMake(10, 150, 210, 20+stringSize.height);
}
else
{
rect = CGRectMake(10, 150, 210, 50);
}
yourtextview.frame=rect;
用户名和testo是texfield还是textview?请尽量保留整个代码,这意味着如果conditon to last将其保留在cell==nill条件下,并运行codeusername是一个“uilabel”,而testo是一个“uitextview”!我试着把所有的东西都放进去,但是桌子不好!