【发布时间】:2015-10-26 15:29:22
【问题描述】:
我正在尝试制作一个与 Instagram 完全一样的带有匿名提要的应用。我使用 AFNetworking 下载 JSON 数据,使用 SDWebImage 添加和缓存图像。
当我加载可变大小的图像时,我希望表格视图单元格自动调整其高度。
现在的问题是,当应用程序加载时,图像无法正确显示,但在我向下滚动并滚动回同一个单元格后,图像会按照我想要的方式自行调整,但图像上方和下方总是有一个空格.
滚动前
回滚后
以下是 UIImage 视图的约束:
- superview 的尾随空格:0
- 领先空间到superview : 0
- 顶部空间:8
- 底部空间:8
- 固有大小设置为占位符,内容模式设置为 Aspect Fit。
这是我的 ViewDidLoad 方法代码:
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.barTintColor = UIColor.yellowColor()
feedList = NSMutableArray()
self.feedTable.rowHeight = UITableViewAutomaticDimension
self.feedTable.estimatedRowHeight = 200.0
var connection : CommunicationManager! = CommunicationManager()
//initiate a connection and load feed data
connection.getFeedData( { (response, error) -> Void in
if(response != nil){
dispatch_async(dispatch_get_main_queue(), {
self.feedList = response
self.feedTable.hidden = false
self.feedTable.reloadData()
})
}
}
TableView 的 CellForRowAtIndex:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! FeedTableViewCell
let feedData : NSDictionary! = feedList[indexPath.row] as! NSDictionary
let imgURL : NSURL! = NSURL(string: feedData.valueForKey("image_name") as! String)
cell.feedImage.sd_setImageWithURL(imgURL, placeholderImage: UIImage(named: "LoadingImage"))
return cell
}
我尽了最大努力解决这个问题,但无法让它发挥作用。谁能告诉我如何使用故事板解决这个问题。 提前致谢。
【问题讨论】:
标签: ios swift uitableview autolayout sdwebimage