Ios TableView存储中的UIImage
我有12幅图像的Ios TableView存储中的UIImage,ios,xcode,swift,uiimage,tableview,Ios,Xcode,Swift,Uiimage,Tableview,我有12幅图像的tableView。每行1个。图像大小为536 x x536 px(804 x 804表示@3x),全部为JPG格式,文件大小约为250kb。当我使用模拟器时,仅该tableView的内存就达到了40MB。是的,我使用了dequeueReusableCellWithIdentifier。以下是截图: 这正常吗?或者我如何改进它?因为我使用了UIImage(名为:…),所以它是缓存的。 我还没有尝试使用真正的设备,仍在等待我的信用卡:) 这里是我的cellforrowatinex
tableView
。每行1个。图像大小为536 x x536 px(804 x 804表示@3x),全部为JPG格式,文件大小约为250kb。当我使用模拟器时,仅该tableView
的内存就达到了40MB。是的,我使用了dequeueReusableCellWithIdentifier
。以下是截图:
这正常吗?或者我如何改进它?因为我使用了UIImage(名为:…)
,所以它是缓存的。
我还没有尝试使用真正的设备,仍在等待我的信用卡:)
这里是我的cellforrowatinexpath
代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let kolom = tableView.dequeueReusableCellWithIdentifier("portraitkolom", forIndexPath: indexPath) as portraitdetailTableViewCell
let portrait = portraits[indexPath.row]
kolom.portraitdetailgambar.image = UIImage(named: portrait.thumbImage)
kolom.portraitdetailgambar.layer.shadowColor = UIColor(red: 200.0/255.0, green: 200.0/255.0, blue: 200.0/255.0, alpha: 1.0).CGColor
kolom.portraitdetailgambar.layer.shadowOffset = CGSizeMake(0, 2)
kolom.portraitdetailgambar.layer.shadowRadius = 0
kolom.portraitdetailgambar.layer.shadowOpacity = 1.0
return kolom
}
更新:
使用UIImage(contentsOfFile:)
似乎有点减少内存使用。
以下是截图:
更新代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let kolom = tableView.dequeueReusableCellWithIdentifier("portraitkolom", forIndexPath: indexPath) as portraitdetailTableViewCell
let portrait = portraits[indexPath.row]
let paths = NSBundle.mainBundle().pathForResource(portrait.thumbImage, ofType: "jpg", inDirectory: "portraitthumb")
kolom.portraitdetailgambar.image = UIImage(contentsOfFile: paths!)
kolom.portraitdetailgambar.layer.shadowColor = UIColor(red: 200.0/255.0, green: 200.0/255.0, blue: 200.0/255.0, alpha: 1.0).CGColor
kolom.portraitdetailgambar.layer.shadowOffset = CGSizeMake(0, 2)
kolom.portraitdetailgambar.layer.shadowRadius = 0
kolom.portraitdetailgambar.layer.shadowOpacity = 1.0
return kolom
}
但它仍然是32MB。。这正常吗?
而且它看起来像是UIImage(contentsOfFile:)
没有检测到@2x或@3x图像(区分大小写?)。。因此,我将我的图像重命名为someimage.jpg(以前)someimage@3x.jpg). 对吗
谢谢。只是为了提高性能。执行以下步骤
只是为了提高性能。执行以下步骤
只是为了提高性能。执行以下步骤
只是为了提高性能。执行以下步骤
如果您想在手机中显示图像,请提供一些提示:
参考。如果您想在手机中显示图像,请提供一些提示: