Высота пользовательской ячейки после инициализации в UITableView - PullRequest
0 голосов
/ 08 ноября 2011

У меня есть таблица с пользовательской ячейкой.Эти клетки имеют разную высоту, и я знаю, как рассчитать высоту.Проблема в том, что метод heightForRowAtIndexPath вызывается перед методом cellForRowAtIndexPath , поэтому я не могу передать CGFloat возврата.

Есть ли способ вызвать этот метод после?

Большое спасибо

EDIT

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

CustomCellFavorites *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

    cell = [[CustomCellFavorites alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    cell.topSuperiore = self;

}

//textviews

NSString *string01 = ((Traduzioni *)[self.arrayTraduzioni objectAtIndex:indexPath.row]).testoOriginale;
NSString *string02 = ((Traduzioni *)[self.arrayTraduzioni objectAtIndex:indexPath.row]).testoTradotto;

[cell loadItem:string01 :string02];

return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCellFavorites *cell = (CustomCellFavorites*)[self tableView:tableView cellForRowAtIndexPath:indexPath];
return cell.heightCell;

}

пользовательский метод ячейки

-(void)loadItem:(NSString *)text01:(NSString *)text02 {
textView01.text = text01;
CGRect rect = textView01.frame;
rect.size.height = textView01.contentSize.height;
textView01.frame = rect;
[tv01Bg setFrame:CGRectMake(32, 0, 288, (textView01.contentSize.height)+20)];
textView02.text = text02;

CGRect rect2 = textView02.frame;
rect2.size.height = textView02.contentSize.height;
textView02.frame = rect2;
[tv02Bg setFrame:CGRectMake(0, (textView01.contentSize.height)+20, 320, (textView02.contentSize.height)+20)];
heightCell = (rect2.origin.y)+(rect2.size.height)+15.5;
 }

1 Ответ

3 голосов
/ 08 ноября 2011

Нет, нет способа вызвать этот метод после.Способ, которым я справился, состоит в том, чтобы получить фактическую строку и в зависимости от типа строки выбрать высоту.Ниже следует некоторый краткий код -

- (CGFloat)tableView:(UITableView *)tableView 
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSObject *res     = [self.resultSet objectAtIndex:[indexPath row]];

    if([res isKindOfClass:[someX class]])
        return 110;
    else if([res isKindOfClass:[someY class]])
        return 120;
    else if([res isKindOfClass:[someZ class]])
        return 230;
    else
        return 175.0;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...