【问题标题】:UITableViewCell UIButton dynamic heightUITableViewCell UIButton 动态高度
【发布时间】:2013-04-29 11:44:30
【问题描述】:

我有CustomCellView,这是表格视图中单元格的自定义视图。我在 xib 中有 UIButton 并在 xib 中设置它的默认框架。

MainViewController (viewDidLoad)

// Get nib for custom cell
UINib *nib = [UINib nibWithNibName:@"CustomFeedCell" bundle:nil];
[self.mainTableView registerNib:nib forCellReuseIdentifier:@"CustomFeedCell"];

在 cellForRow...

CustomFeedCell *cell = [self.mainTableView dequeueReusableCellWithIdentifier:@"CustomFeedCell"];

// here i need to set UIButton frame (height) depending on image height.
// I have tried diferent ways and it always return height set in CustomCellView xib

【问题讨论】:

    标签: objective-c uitableview uibutton frame


    【解决方案1】:

    如果你想在UIView动态创建按钮、图片等,你必须使用viewDidLoad:方法,不要使用xibs。

    【讨论】:

      【解决方案2】:

      好的,我从您的问题中了解到,您在设置 tableview 单元格中存在的按钮的动态高度时遇到问题。有时它可能高于单元格的高度,有时安静低于单元格的高度。你想相应地调整它。对吗?

      如果那是您的问题,那么您可以在其委托中设置每个 tableview 单元格的高度 表视图:heightForRowAtIndexPath:

      作为

      - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
      {
          return [indexPath row] * 20; // your desired height
      }
      

      希望这能解决您的问题。

      【讨论】:

        猜你喜欢
        • 2016-07-27
        • 1970-01-01
        • 2019-10-12
        • 2011-06-20
        • 1970-01-01
        • 2014-12-15
        • 2015-12-09
        • 2011-06-04
        相关资源
        最近更新 更多