我在UITableView单元格中显示来自服务器的数据有一个小问题.我有一个添加显示"提要"屏幕,类似于Instagram上的主屏幕.Feed的UITableView中的每个单元格都加载和映像以及来自服务器的一些文本(来自parse.com)
这是我的cellForRowAtIndexPath实现:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(HomeCell.reuseIdentifier(), forIndexPath: indexPath) as HomeCell
// Configure the cell...
let obj = tableArray[indexPath.section]
cell.configureWithObject(obj)
return cell
}
Run Code Online (Sandbox Code Playgroud)
tableArray是一个PFObjects数组
在HomeCell类中,configureWithObject方法使用SDWebImage加载此单元格的远程图像并设置所需的文本标签
func configureWithObject(object : PFObject) {
AppManager.sharedInstance().getTrackDetailsFromPost(object, block: { (error, obj) -> Void in
if error != nil
{
return
}
var artworkURL = ""
if let artworkString = obj?[Column.TracksArtwork.rawValue] as? String {
artworkURL = artworkString
}
self.albumArtwork.sd_setImageWithPreviousCachedImageWithURL(NSURL(string: artworkURL))
var trackTitle = ""
if let title = …Run Code Online (Sandbox Code Playgroud)