无法将图像放在tableviewcell中

时间:2015-08-19 15:30:35

标签: ios swift storyboard

我有其他表工作正常,但这个表不起作用。图像不留在细胞内(见小线):

enter image description here

enter image description here

我想要这个:

enter image description here

模式是Aspect to Fit,但是我已经尝试了所有东西,似乎没有任何效果。

我的代码:

import UIKit
import Parse

class PratosViewController:             UIViewController,UITableViewDataSource,UITableViewDelegate {

  var restauranteRow: PFObject!

@IBOutlet var tableView: UITableView!

@IBOutlet var Scroller: UIScrollView!
@IBOutlet var tituloRestaurante: UILabel!
@IBOutlet var imagemRestaurante: UIImageView!
override func viewDidLoad() {
    super.viewDidLoad()
    Scroller.contentInset = UIEdgeInsetsMake(0, 0, 400, 0)
    navigationController?.navigationBar.tintColor = UIColor.blackColor()


    tituloRestaurante.text = restauranteRow["nome"] as? String

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()

    self.Scroller.frame = self.view.bounds
    self.Scroller.contentSize.height = 400
    self.Scroller.contentSize.width = 0
}



//TableView
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = self.tableView.dequeueReusableCellWithIdentifier("ceculaPratos") as! PratosTableViewCell

    let imagem = restauranteRow["imagem1"] as! PFFile
    imagem.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in

        if (error == nil) {

            cell.imagemCelula.image = UIImage(data:imageData!)

        }
    }



    return cell
}


}

1 个答案:

答案 0 :(得分:1)

创建自定义单元格并添加自动布局约束以满足单元格内的图像尺寸