【问题标题】:Xcode UITableView Custom Cell xib Image HeightXcode UITableView 自定义单元格xib 图像高度
【发布时间】:2014-03-06 07:21:20
【问题描述】:

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

【问题讨论】:

  • 发布您的相关代码
  • 在 CellForRowAtIndexPath 中,您将创建一个 UIImageView 并增加特定索引的单元格高度。
  • 为此创建一个自定义表格单元格。 appcoda.com/customize-table-view-cells-for-uitableview 的示例
  • 图片来自本地还是网络
  • 我创建了自定义表格单元格,但是图像大小都一样,我有 2 个图像视图并且所有图像高度都是不同的高度,所以我想显示具有原始图像大小的图像

标签: ios xcode uitableview


【解决方案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;
}

【讨论】:

    【解决方案2】:

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

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
    CGFloat cellHeight = image1height + image2height + <button height>;
    
    return cellHeight;
    
    }
    

    还需要根据图片动态分配自定义单元格中的imageView rect。

    【讨论】:

    • 我现在不知道如何获取图像大小,我添加了我的代码,请 RAJA SAB 你能帮我解决这个问题吗
    • 有一个属性可以获取 uiimage 大小。看到这个链接..stackoverflow.com/questions/5249664/…
    【解决方案3】:

    这是我的代码

    - (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;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-11-27
      • 1970-01-01
      • 2012-01-07
      • 2021-09-17
      • 2018-02-13
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      相关资源
      最近更新 更多