我有一个表视图,
我有一个数据库使用Firebase获取一些数据:标题,标题,图像。
标题和标题显示完美,并从Firebase中获取。但是,没有图像出现。 ..
任何帮助都会令人惊叹:) :)
我的View控制器的代码如下:
<div class="myTabs">
<ul class="tabs" data-tab data-options="deep_linking:true">
<li><a data-toggle="tab" href="#One">Tab 1</a></li>
<li><a data-toggle="tab" href="#Two">Tab 2</a></li>
</ul>
</div>
<div class="tabContent">
<div id="One">This is the content in div one on Tab 1</div>
<div id="AnotherOne">This is the content is second div on Tab 1</div>
</div>
要调用图像,我有以下内容:cell.swift
//
// 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()
}
}
-
我已使用以下内容更新了我的feed.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()
}
}
使用SDWebImage - 但我仍然没有显示任何图像:(
答案 0 :(得分:0)
您没有看到任何图片,因为您从未设置过它们。您需要在{
_id: someid,
createdAt: new Date(),
message: somemessage,
eadd: eadd
}
configureCell