Как я могу получить высоту определенной строки в UITableView

В моем UITableView я установил разные высоты для разных строк, используя метод делегата: tableView:heightForRowAtIndexPath:

Теперь, учитывая NSIndexPath, я хотел бы получить высоту, которую я ранее назначил для определенной строки.

Ответы

Ответ 1

Вы можете использовать этот

CGRect frame = [tableView rectForRowAtIndexPath:indexPath];
NSLog(@"row height : %f", frame.size.height);

Используя frame.size.height, вы можете получить высоту определенной строки

Swift 3

let frame = tableView.rectForRow(at: indexPath)
print(frame.size.height)

Ответ 2

Просто используйте

Tableview: heightForRowAtIndexPath

Метод

int row = 1;

int section = 0;

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];

float height = [self tableView:tableView heightForRowAtIndexPath:indexPath];

Надеюсь, что эта помощь поможет вам:)

Ответ 3

-(CGFloat)getHeightAtIndexPath:(NSIndexPath *)indexPath{
   if(indexPath.row == 0)
       return 20.0;
   else if(indexPath.row == 4)
       return 40.0;

  return 50.0; //Default

}

Вызвать вышеуказанную функцию в tableView:heightForRowAtIndexPath: как

return [self getHeightAtIndexPath:indexPath];

И вы можете использовать одну и ту же функцию, нажав кнопку нажатия кнопки кнопки внутри конкретной ячейки, имея button.tag=indexPath.row

-(IBAction)btnClick:(id)sender{
   UIButton *btn=(UIButton *)sender;

   NSIndexPath *indexPath=[NSIndexPath indexPathForRow:btn.tag inSection:0];

   CGFloat height=[self getHeightAtIndexPath:indexPath];

}

Ответ 4

 let height = super.tableView(tableView, heightForRowAt: indexPath)