-3

我通过这段代码创建了一个 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 的高度,我很困扰我。我需要帮助,谢谢!

4

1 回答 1

0

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

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // ------------- add your more stuff here ---------------
    if(indexPath.row == 0)
      return yourHeight;
}
于 2013-07-29T10:26:43.173 回答