【问题标题】:I want dynamic get height of UITableViewCell我想要动态获取 UITableViewCell 的高度
【发布时间】:2013-07-29 02:15:34
【问题描述】:

我通过这段代码创建了一个 TableView:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
        {
            return 1;
        }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
        {
            return 100;
        }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            static NSString *cellString = @"cellString";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellString];
            if(cell == nil)
            {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString];
                NSLog(@"count : %d",count++);
    }
            return cell;
        }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
            return cell.frame.size.height;
        }

我发现这个 TableView 没有被重用,但是我想要动态获取 TableViewCell 的高度,我很困扰我。我需要帮助,谢谢!

【问题讨论】:

  • 你为什么要调用 [self tableView:tableView heightForRowAtIndexPath:indexPath];方法
  • 有什么方法可以动态获取TableViewCell的高度吗?

标签: ios uitableview height


【解决方案1】:

不需要获取 tableviewcell 的高度。因为您可以直接返回特定单元格的高度...

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // ------------- add your more stuff here ---------------
    if(indexPath.row == 0)
      return yourHeight;
}

【讨论】:

  • 但现在我不知道它的高度
  • 如果你不知道在这种情况下你需要计算动态。
猜你喜欢
  • 2013-06-28
  • 1970-01-01
  • 2016-05-05
  • 2016-07-27
  • 1970-01-01
  • 1970-01-01
  • 2019-10-12
  • 2011-06-20
相关资源
最近更新 更多