Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 动态更改TableView单元格高度_Ios_Objective C_Iphone_Swift - Fatal编程技术网

Ios 动态更改TableView单元格高度

Ios 动态更改TableView单元格高度,ios,objective-c,iphone,swift,Ios,Objective C,Iphone,Swift,Swift/Objective C-动态更改TableView单元格高度的简单方法 在我的表格视图中,单元格分隔第一行和第三行,每个标签都将是动态的 为图像视图添加约束(顶部、前导、尾部、高度) 不添加底部约束 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReu

Swift/Objective C-动态更改TableView单元格高度的简单方法

在我的表格视图中,单元格分隔第一行和第三行,每个标签都将是动态的


为图像视图添加约束(顶部、前导、尾部、高度)

不添加底部约束

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCellWithIdentifier("PropertyListCell", forIndexPath: indexPath) as UITableViewCell!

    imgProperty = viewBg.viewWithTag(111) as! RemoteImageView
    lblPropertyName = viewBg.viewWithTag(112) as! UILabel
    lblPrice = viewBg.viewWithTag(113) as! UILabel
    lblAddress = viewBg.viewWithTag(114) as! UILabel
    lblAreaPerSquare = viewBg.viewWithTag(115) as! UILabel

    imgProperty.imageURL = NSURL(string: "Image Url")
    lblPropertyName.text="Jai Maharashtra Apartment"
    lblPrice.text="Rs. 900 - 10000"
    lblAddress.text="411041,Maharashtra Sadan, Pune, Maharashtra , India" // just address changed. 
    lblAreaPerSquare.text="500 Square Meter"

    cell.selectionStyle = UITableViewCellSelectionStyle.None
    return cell
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
    return UITableViewAutomaticDimension
}

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
    return 44.0
}


为每个标签添加约束(顶部、前导、尾部、底部)


将约束添加到最后一个标签(顶部、前导、尾随、底部)

设置每个标签

行数=0

换行模式=字扭曲

表视图数据源和委托方法

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCellWithIdentifier("PropertyListCell", forIndexPath: indexPath) as UITableViewCell!

    imgProperty = viewBg.viewWithTag(111) as! RemoteImageView
    lblPropertyName = viewBg.viewWithTag(112) as! UILabel
    lblPrice = viewBg.viewWithTag(113) as! UILabel
    lblAddress = viewBg.viewWithTag(114) as! UILabel
    lblAreaPerSquare = viewBg.viewWithTag(115) as! UILabel

    imgProperty.imageURL = NSURL(string: "Image Url")
    lblPropertyName.text="Jai Maharashtra Apartment"
    lblPrice.text="Rs. 900 - 10000"
    lblAddress.text="411041,Maharashtra Sadan, Pune, Maharashtra , India" // just address changed. 
    lblAreaPerSquare.text="500 Square Meter"

    cell.selectionStyle = UITableViewCellSelectionStyle.None
    return cell
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
    return UITableViewAutomaticDimension
}

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
    return 44.0
}
现在所有标签都是动态的


Swift-3.0

 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
     var height:CGFloat = CGFloat()
     if indexPath.row == 0 {
     height = 80
    }
    else if indexPath.row == 1 {
     height = self.view.frame.size.height - 80 - 44 - 64
     print(height)
    }
    return height
   }

这个答案的可能副本有图像提及的每个步骤,每个步骤都很容易理解……确实是非常好的答案!祝贺你。:-)Thanx bro提供解决方案。