Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当单元格包含带新行字符的uilabel时,heightForRowAtIndexPath不正确_Ios_Uitableview - Fatal编程技术网

Ios 当单元格包含带新行字符的uilabel时,heightForRowAtIndexPath不正确

Ios 当单元格包含带新行字符的uilabel时,heightForRowAtIndexPath不正确,ios,uitableview,Ios,Uitableview,我想在uitableviewcell中显示地址信息,并且正在使用带有自动布局的自定义单元格。我想,与其为地址字段设置单独的标签,不如使用一个标签,将地址字段连接在一起,并使用换行符“\n”使每个地址字段显示在标签中的新行上,然后将行的标签数设置为零,以便自动展开 这部分工作正常,但不起作用的是,当我试图计算RowAtIndexPath的高度时,它未报告标签大小,因此地址被截断 e、 g.这里是一些代码提取:看起来boundingRectWithSize可能没有考虑换行符?无论如何,我不想使用单个

我想在uitableviewcell中显示地址信息,并且正在使用带有自动布局的自定义单元格。我想,与其为地址字段设置单独的标签,不如使用一个标签,将地址字段连接在一起,并使用换行符“\n”使每个地址字段显示在标签中的新行上,然后将行的标签数设置为零,以便自动展开

这部分工作正常,但不起作用的是,当我试图计算RowAtIndexPath的高度时,它未报告标签大小,因此地址被截断

e、 g.这里是一些代码提取:看起来boundingRectWithSize可能没有考虑换行符?无论如何,我不想使用单个标签,而是有单独的字段,这将需要更多的工作,但我认为不会遇到这些问题

        NSString *description= [self getAddressDescription:_delegate.shoppingCart.shippingAddress]; // formats address fields into single string with newline characters 
NSAttributedString *attributedText =
                [[NSAttributedString alloc]
                        initWithString:description
                            attributes:@
                            {
                                    NSFontAttributeName: [ViewHelper getDescriptionFont]
                            }];

CGRect rect = [attributedText boundingRectWithSize:(CGSize){200, CGFLOAT_MAX}
                                                   options:NSStringDrawingUsesLineFragmentOrigin
                                                   context:nil];
CGSize descriptionSize = rect.size;
return kParentChildDefaultSpace + + descriptionSize.height + kParentChildDefaultSpace;

您可以将原型单元方法与
[label sizeToFit]
结合使用