テーブルビューの自動サイズ変更はテーブルビューの高さと同じように変更されます。そのために私はこのコードを使用していますUiButtonの位置はプログラムによって変更されません
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
}
私はこの機能を実行することができます。
私はテーブルビューにボタンボトムを追加しています。 は、テーブルビューのどんなサイズがthere.buttonは、テーブルビューから常にトップであるべきであるので、私はこれをやっている私は、このコード
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])
を使用していますテーブルビューからトップの位置を設定します。
しかし、これは機能しません。ここでは、エラーのスクリーンショットは、
の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