我在xcode中制作一个ios应用程序制作了一个表格视图,并在视图控制器上方添加了一个图像,并将它们两个都视为红色视图和表格视图但是当我向下拖动表格视图直到结束时是白色而不是红色。你能告诉我如何在事先修好Thnx;)
代码:
import UIKit
import Firebase
import FirebaseDatabase
import PINRemoteImage
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var ref:FIRDatabaseReference!
var data = [DataModel]()
@IBOutlet weak var one: UIImageView!
@IBOutlet weak var mytable: UITableView!
override func viewDidLoad() {
doSetup()
self.view.backgroundColor = UIColor(red: 138/255, green: 56/255, blue: 48/255, alpha: 1.0)
mytable.dataSource = self
mytable.delegate = self
super.viewDidLoad()
}
func doSetup(){
ref = FIRDatabase.database().reference()
//ref.child("Posts").childByAutoId().setValue(["post_text":" Nami ","imageUrl" : ""])
ref.child("Posts").observe(.childAdded, with: { (snapshot) in
let newData = snapshot.value as! [String:String]
let post_text = newData["post_text"]
let imageUrl = newData["imageUrl"]
let converted = DataModel(post_text: post_text, imageUrl: imageUrl)
self.data.append(converted)
self.mytable.reloadData()
self.one.pin_setImage(from: URL(string : "https://otaku-w9pxf76zfsktmx3e.stackpathdns.com/wp-content/uploads/2016/06/Luffy.png"))
})
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell
let nth_data = data[indexPath.row]
cell.posttext.text = nth_data.post_text
cell.posttext.textColor = .white
cell.myimage.pin_setImage(from: URL(string: nth_data.imageUrl!))
cell.backgroundColor = UIColor(red: 138/255, green: 56/255, blue: 48/255, alpha: 1.0)
return (cell)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
}