Xcode UITableView自定义单元格xib图像高度

时间:2014-03-06 07:21:21

标签: ios xcode uitableview

请看这张照片并帮助我,这对我来说非常重要。非常感谢你

enter image description here

3 个答案:

答案 0 :(得分:1)

我会为此实现heightforRowAtIndexPath,简而言之:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//first image height must be fetched for the ccurrent image using indexpath.row...

//Then use the height to set cell height:
    return imageHeight;
}

答案 1 :(得分:0)

需要自定义自定义单元格的高度,还需要根据图像调整自定义单元格内的图像视图大小

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

CGFloat cellHeight = image1height + image2height + <button height>;

return cellHeight;

}

还需要根据图像动态地在自定义单元格中指定imageView rect。

答案 2 :(得分:0)

这是我的代码

- (void)viewDidLoad {
    [super viewDidLoad];

    tableData = [NSArray arrayWithObjects:@"1.png", @"2.png", @"3.png", @"4.png", nil];

}


#pragma mark **** TableView ***
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [tableData count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    static NSString *listTableIdentifier = @"CustomCell";
    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:listTableIdentifier];


    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }


    cell.myImage1.image = [UIImage imageNamed:[tableData objectAtIndex:indexPath.row]];

    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 85;
}
相关问题