我正在做tableview的自动调整tableview的高度会根据其内容而改变。为此,我正在使用此代码UiButton通过编程方式不改变位置ios
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
dispatch_async(dispatch_get_main_queue(),{
self.tblReceipt.sizeToFit()
var frame = self.tblReceipt.frame
frame.size.height = self.tblReceipt.contentSize.height
self.tblReceipt.frame = frame
}
我能够做到这一点。
比我添加按钮底部到tableview。 设置从tableview中顶位置,我使用此代码
let pinTop = NSLayoutConstraint(item: self.btnPrint, attribute: .Top, relatedBy: .Equal,
toItem: self.tblReceipt, attribute: .Bottom, multiplier: 1.0, constant: 10)
self.btnPrint.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activateConstraints([pinTop])
我这样做是因为任何的tableview的大小是there.button应该始终从顶部的tableview。
但这不起作用。下面是错误的屏幕截图
的UITableView委托方法
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrReceipt.count
}
数据源方法
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:PrintCell = (tblReceipt.dequeueReusableCellWithIdentifier("PrintCell"))! as! PrintCell
cell.lblProductName.text = arrReceipt[indexPath.row].objectForKey("product_name") as? String
cell.lblProductPrice.text = String(format:"%.2f", arrReceipt[indexPath.row]["product_price"]!!.doubleValue)
return cell
}
是exactly.i想这 –
@pedrouan请检查我的更新question.i添加图片我想在我的应用程序。 –
@KrutarthPatel表格高度不会在添加新单元格时发生变化,因此您的按钮将保持在同一位置。表格高度保持不变,并且在增加行数时会增加额外的行。 – raki