2017-02-08 20 views
0

显示在表格单元格我有一个表视图,图像不从火力

我有个DB使用火力地堡取一些数据:标题,说明图像。

标题和标题显示完美,正在从Firebase中获取。但是,没有图像出现。 ..

任何帮助将是惊人的,请:) :)

我的视图控制器的代码如下:

// 
// Feed.swift 
// MobileAppDemo 
// 
// Created by Mikko Hilpinen on 31.10.2016. 
// Copyright © 2016 Mikkomario. All rights reserved. 
// 

import UIKit 
import FirebaseAuth 
import FirebaseDatabase 
import FirebaseStorage 
import SwiftKeychainWrapper 
import SwiftyJSON 

var posts = [Post]() 
var selectedIndexPath: Int = 0 

class FeedVC: UIViewController, UITableViewDataSource, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITableViewDelegate { 

@IBOutlet weak var feedTableView: UITableView! 

private var readPosts: ObserveTask? 

@IBOutlet weak var imageView: UIImageView! 

override func viewDidLoad() { 
    super.viewDidLoad() 

    feedTableView.dataSource = self 
    feedTableView.delegate = self 

    readPosts = Post.observeList(from: Post.parentReference.queryOrdered(byChild: Post.PROPERTY_CREATED)) { 
     observedPosts in 

     posts = observedPosts.reversed() 
     self.feedTableView.reloadData() 
    } 
} 

func numberOfSections(in tableView: UITableView) -> Int { 
    return 1 
} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return posts.count 
} 

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
    return UITableViewAutomaticDimension 
} 

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { 
    return UITableViewAutomaticDimension 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = self.feedTableView.dequeueReusableCell(withIdentifier: "MessageCell")! as UITableViewCell 

    let messageImageView = cell.viewWithTag(1) as! UIImageView 
    let titleLabel = cell.viewWithTag(2) as! UILabel 
    let captionText = cell.viewWithTag(3) as! UILabel 


    titleLabel.text = posts[indexPath.row].title 
    titleLabel.numberOfLines = 0 

    captionText.text = posts[indexPath.row].caption 
    captionText.numberOfLines = 0 


    return cell 

} 

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    selectedIndexPath = indexPath.row 
    self.performSegue(withIdentifier: "push", sender: self) 
    self.feedTableView.reloadData() 
} 
} 

要调用我有后续图像中我cell.swift

// 
// MessageCell.swift 
// MobileAppDemo 
// 
// Created by Mikko Hilpinen on 31.10.2016. 
// Copyright © 2016 Mikkomario. All rights reserved. 
// 

import UIKit 
import FirebaseStorage 


class MessageCell: UITableViewCell 
{ 
// @IBOutlet weak var profileImageView: UIImageView! 
// @IBOutlet weak var likeButton: UIButton! 

@IBOutlet weak var messageImageView: UIImageView! 
@IBOutlet weak var messageTextView: UITextView! 
@IBOutlet weak var titleTextView: UITextView! 
@IBOutlet weak var linkbutton: UIButton! 

// @IBOutlet weak var likeLabel: UILabel! 

private var post: Post! 

func configureCell(tableView: UITableView, post: Post) 
{ 
    self.post = post 

    // Basic info 
    //  self.messageImageView.image = postPic 

    messageImageView.image = post.postPic 
    titleTextView.text = post.title 
    messageTextView.text = post.caption 


    // Post user 
    User.get(id: post.creatorId) 
    { 
     postCreator in 




    // Image 
    Storage.getImage(with: post.imageUrl) 
    { 
     postPic in 

     self.messageImageView.image = postPic 
     // Row height changes so table needs to be reset 
     tableView.beginUpdates() 
     tableView.endUpdates() 
    } 
} 

-

我已经更新了我feed.swift有以下几点:

messageImageView.sd_setImage(with: URL(string:"\(posts[indexPath.row].imageUrl)")) 

使用SDWebImage - 但IM仍然没有任何图像显示是:(

回答

0

你没有看到任何图像,因为你从来没有设置。您需要拨打configureCell以内cellForRowAt

+0

嗯,谢谢罗素,你知道这怎么能实现? 谢谢:) – tibewww

+0

只是在'cellForRowAt'内调用 - 但是你的Cell类有点奇怪。你不应该在单元格内重新加载'tableView',你根本不需要引用'tableView'。此外,您已为某些正在使用的控件创建了插座,但您忽略了插座并使用标签值访问控件。 – Russell

+0

好吧,我尽我所能,我开始与ios开发,所以我不是sur能够做到这个ehehe – tibewww