cellForRowAtIndexPath中的rowHeight不变

时间:2013-01-20 19:46:10

标签: iphone objective-c cocoa-touch uitableview

我有一个rowHeight的问题,似乎没有改变(虽然我在方法heightForRow中这样做...)

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.section == 0 && indexPath.row == 0) {
        return 80;
    } else
        return 0;
}

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    [cell setSelectionStyle:UITableViewCellSeparatorStyleNone];

    // Configure the cell...


    if(indexPath.section == 0 && indexPath.row == 0) {

        NSLog(@"frame.size.height: %f rowHeight: %f", cell.frame.size.height, tableView.rowHeight);
    }

    return cell;
}

两个值都是44.0000:cell.frame.size.height和rowHeight。

以下是如何在navcontroller中初始化此表:

DPSettingsInformations *settingsInformations = [[DPSettingsInformations alloc] initWithStyle:UITableViewStyleGrouped];
    [self.navigationController pushViewController:settingsInformations animated:YES];

1 个答案:

答案 0 :(得分:3)

44是默认高度,因此听起来好像没有设置UITableViewDelegate

tableView:heightForRowAtIndexPath:要求设置UITableViewDelegate。确保在Nib,Storyboard或代码中正确设置了此项。通常您可以在UITableViewDataSource

的同时进行设置

示例(如果在代码中设置):

// UITableViewDataSource delegate
self.tableView.dataSource = self;
// UITableViewDelegate delegate
self.tableView.delegate = self;