Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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:在UITableViewCell中创建自调整大小的UITextView?_Ios_Iphone_Objective C_Uitableview - Fatal编程技术网

IOS:在UITableViewCell中创建自调整大小的UITextView?

IOS:在UITableViewCell中创建自调整大小的UITextView?,ios,iphone,objective-c,uitableview,Ios,Iphone,Objective C,Uitableview,我正在为我的项目使用stroyboards。我的项目基于解析json数据并用json显示它。在解析JSON时,我将收到两个不同的数据。标题和说明 我必须解析它,并且必须在uitableviewcell内的UItextview中进行修复我已经构建了这样一个uitableviewcell 文本视图,文本视图,标签,标签,标签,标签,标签,标签; 现在我的问题是,我的文本视图必须根据数据调整大小,并且基于tableviewcell也必须调整大小,我尝试了上面的代码,但是视图会崩溃 - (UITable

我正在为我的项目使用stroyboards。我的项目基于解析json数据并用json显示它。在解析JSON时,我将收到两个不同的数据。标题和说明 我必须解析它,并且必须在uitableviewcell内的UItextview中进行修复我已经构建了这样一个uitableviewcell

文本视图,文本视图,标签,标签,标签,标签,标签,标签; 现在我的问题是,我的文本视图必须根据数据调整大小,并且基于tableviewcell也必须调整大小,我尝试了上面的代码,但是视图会崩溃

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"Need_Request";
    NeedReqListCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];
    type = (NSString *)[array4 objectAtIndex:indexPath.row];
    if([type isEqualToString:@"Money Donation"]) {
        cell.createdby.text = (NSString *)[array3 objectAtIndex:indexPath.row];
        cell.product.text = (NSString *)[array4 objectAtIndex:indexPath.row];
        cell.expiration.text = (NSString *)[array5 objectAtIndex:indexPath.row];
        cell.titleview.text = (NSString *)[array1 objectAtIndex:indexPath.row];
        [cell.descview setHidden:TRUE];
        [cell.totalquantity setHidden:TRUE];
        [cell.fulfilledquantity setHidden:TRUE];
        return cell;

    }
    else if([type isEqualToString:@"Service"]) {
        cell.createdby.text = (NSString *)[array3 objectAtIndex:indexPath.row];
        cell.product.text = (NSString *)[array4 objectAtIndex:indexPath.row];
        cell.expiration.text = (NSString *)[array5 objectAtIndex:indexPath.row];
        cell.titleview.text = (NSString *)[array1 objectAtIndex:indexPath.row];
        cell.descview.text = (NSString *)[array2 objectAtIndex:indexPath.row];
        [cell.totalquantity setHidden:TRUE];
        [cell.fulfilledquantity setHidden:TRUE];
        return cell;

    }

    cell.createdby.text = (NSString *)[array3 objectAtIndex:indexPath.row];
    cell.product.text = (NSString *)[array4 objectAtIndex:indexPath.row];
    cell.expiration.text = (NSString *)[array5 objectAtIndex:indexPath.row];
    cell.totalquantity.text = (NSString *)[array6 objectAtIndex:indexPath.row];
    cell.fulfilledquantity.text = (NSString *)[array7 objectAtIndex:indexPath.row];
    cell.titleview.text = (NSString *)[array1 objectAtIndex:indexPath.row];
    cell.descview.text = (NSString *)[array2 objectAtIndex:indexPath.row];
    CGRect bodyFrame = cell.titleview.frame;
    bodyFrame.size = cell.titleview.contentSize;
    [cell.titleview setFrame:bodyFrame];
    CGRect bodyFrame1 = cell.descview.frame;
    bodyFrame1.size = cell.descview.contentSize;
    [cell.descview setFrame:bodyFrame1];
    CGRect bodyFrame2 = cell.createdby.frame;
    [cell.createdby setFrame:bodyFrame2];
    CGRect bodyFrame3 = cell.product.frame;
    [cell.product setFrame:bodyFrame3];
    CGRect bodyFrame4 = cell.expiration.frame;
    [cell.expiration setFrame:bodyFrame4];
    CGRect bodyFrame5 = cell.totalquantity.frame;
    [cell.totalquantity setFrame:bodyFrame5];
    CGRect bodyFrame6 = cell.fulfilledquantity.frame;    
     [cell.fulfilledquantity setFrame:bodyFrame6];


    return cell;

}
当我尝试这段代码时,我的屏幕如下所示

请帮助我解决此问题

检查此链接-

它将解释如何调整UIlabel的大小以适应内容


另一个建议是使用单个控件,并使用NSFormatted文本,而不是使用这么多标签。同样,这取决于您的要求。

您还需要移动标签的框架原点,以便将它们放置在彼此下方。因此,在计算第一个textView的大小和边界后,将第二个textView的原点设置为第一个textView底部的偏移量。但当你不得不考虑不同的方向和设备屏幕尺寸时,这就变得复杂了


为什么不使用自动布局和约束

但是我需要在uitextview中设置它。我还需要在UITableViewCell中设置它您的文本视图是否可编辑?如果不是,则可以使用单个控件。并使用NSAttributedString格式化文本。我不知道reg自动布局和约束。你能帮我找到可能的解决方案吗?请看本教程:。