English 中文(简体)
要从下到上计算表格中的单元格
原标题:To calculate cell in table from bottom to top

我需要从底部到顶部计算单元格的高度, 正如我在第一个单元格中需要其它单元格的高度总和。 如何计算第一个单元格的最后一个高度, 然后是最后一个单元格的第二个高度. 以及最后第一个单元格高度。 请帮助 。 我在这里的支架非常差。 我的代码是这样的... 它从上到下给出了高度 。

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

    if (indexPath.section==0 && currentQuestion.graphic){       
        UIImage *img= [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:currentQuestion.graphic ofType:nil]];
        self.currentQuestionImage=img;
        [img release];

        return (self.currentQuestionImage.size.height* [self zoomFactor])+10;
    }else if ((indexPath.section==0 && !currentQuestion.graphic) || (indexPath.section==1 && currentQuestion.graphic)){

        CGSize constSize = { self.view.frame.size.width, 20000.0f };
        CGSize textSize = [currentQuestion.text sizeWithFont:[ThemeSettings fontUsedInQuestionCell] constrainedToSize:constSize lineBreakMode:UILineBreakModeWordWrap];
        CGFloat height =  (textSize.height)+60.0;

        return height<45.0?45.0:height;  


        }else if([self answerGraphic: indexPath]){
        UIImage *img = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[self answerGraphic: indexPath] ofType:nil]];
        [self.answerImages replaceObjectAtIndex:indexPath.section withObject:img];
        int size = (img.size.height*0.50)+10;
        [img release];

        return size;

    }else {
        int answerIndex = currentQuestion.graphic?indexPath.section-2:indexPath.section-1;
        Answer *a=[currentQuestion.answers objectAtIndex:answerIndex];
        CGSize constSize = { 300.0f, 20000.0f };
        CGSize textSize = [a.text sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:constSize lineBreakMode:UILineBreakModeWordWrap];
        CGFloat height =  (textSize.height+textSize.height/3.0 )+10.0;
        return height<55.0?55.0:height;


    }

}

请救救我

问题回答

您无法强制执行计算顺序 。 但 hileightForRowAtIndexPath 可以随时计算任何高度。 因此, 类似此行的某样东西会有效 :

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0)
    {
        CGFloat h = 0;
        for (int i = 1; i < [self tableView:tableView numberOfRowsInSection:indexPath.section]; i++)
            h += [self tableView:tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:indexPath.section]];
        return h;
    }
    else
    {
        return 44.; //or any other value for your other cells
    }
}




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签