Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Objective c TableView和RowAtIndexPath的高度_Objective C_Ios_Xcode_Height_Tableview - Fatal编程技术网

Objective c TableView和RowAtIndexPath的高度

Objective c TableView和RowAtIndexPath的高度,objective-c,ios,xcode,height,tableview,Objective C,Ios,Xcode,Height,Tableview,我希望每篇文章在多行中显示完整的标题,每个单元格根据文本标题字符编号有自己的自定义高度。我这样做了,但不起作用。我认为每个对象都应该单独调用。我怎样才能做到这一点?这是我的密码: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { PFObject *object1 = [PFObject objectWithClassName:@"Posts"

我希望每篇文章在多行中显示完整的标题,每个单元格根据文本标题字符编号有自己的自定义高度。我这样做了,但不起作用。我认为每个对象都应该单独调用。我怎样才能做到这一点?这是我的密码:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    PFObject *object1 = [PFObject objectWithClassName:@"Posts"];
    NSString *string1 = [object1 objectForKey:@"text"];
    NSLog(@"%@",string1);



    CGSize theSize = [string1 sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(265.0f, 9999.0f) lineBreakMode:UILineBreakModeWordWrap];
    // numberOfTextRows is an integer.

    numberOfTextRows = (round(theSize.height/14));

    if ((indexPath.row== 0) || (numberOfTextRows <2)) {
        return 44;
    }

    else {
        return theSize.height +18;
    }
}
-(CGFloat)tableView:(UITableView*)tableView rowatinexpath的高度:(nsindepath*)indepath{
PFObject*object1=[pfobjectobjectwithclassname:@“Posts”];
NSString*string1=[object1 objectForKey:@“text”];
NSLog(@“%@”,字符串1);
CGSize theSize=[string1 sizeWithFont:[UIFont systemFontOfSize:14.0f]constrainedToSize:CGSizeMake(265.0f,9999.0f)lineBreakMode:UILineBreakModeWordWrap];
//numberOfTextRows是一个整数。
numberOfTextRows=(圆形(尺寸高度/14));

如果((indexPath.row==0)| |(numberOfTextRows这是我的解决方案。根据需要自定义

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellText;
    CGRect screenBound = [[UIScreen mainScreen] bounds];
    CGSize screenSize = screenBound.size;
    CGFloat screenWidth = screenSize.width;
    CGFloat screenHeight = screenSize.height;

    if (searchDisplayController.active && [searchResults count]) {
        cellText = [searchResults objectAtIndex:indexPath.row];
    } else {
        cellText = [detailPeriodsContent objectAtIndex:indexPath.row];
    }
    UIFont *cellFont = [UIFont systemFontOfSize:14];
    CGSize constraintSize = CGSizeMake(screenWidth-40, MAXFLOAT);
    CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

    return labelSize.height + 35;
}

您是否尝试过从heightForRowAtIndexPath方法中删除逻辑并输入一个固定的数字?然后,您可以查看是否是您的逻辑导致了问题。如果日志显示为null,则问题不在您发布的代码中,而是与object1有关。object1是否也为null?请尝试记录它并查看结果。@rdelmar thobject1的日志是{}。也许我可以创建一个数组来存储对象的所有值,然后调用它们?这样行吗?该代码的另一个问题是,每次调用该方法(每行一次)时,string1(如果你能让它工作)都是相同的。每次调用该方法时,您应该基于indexPath访问不同的字符串。“我应该使用哪一页?”我不知道这意味着什么。