【发布时间】:2015-02-19 03:00:44
【问题描述】:
我有 tableView 有 12 张图片。每行 1 个。图像大小为 536 x x536 像素(@3x 为 804 x 804),全部为 JPG 格式,文件大小约为 250kb。当我使用模拟器时,只有tableView 的内存达到 40MB。是的,我用过dequeueReusableCellWithIdentifier。这是截图:
正常吗?或者我该如何改进它?因为我使用UIImage(named:....) 所以它被缓存了。
我还没有尝试使用真实设备,仍在等待我的信用卡.. :)
这是我的cellForRowAtIndexPath 代码:
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)。对吗?
谢谢。
【问题讨论】:
-
您的图像是存储在您的应用程序中还是从网络上检索的?请附上您如何获取图像的代码并将它们放入您的 UITableViewCell。
-
所有图片都捆绑在应用中。
-
@jeraldo :添加了代码。谢谢。
标签: ios xcode swift uiimage tableview