I am making an application with a base in firebase. I need to split the data into sections and cells and add a picture to the cells. but now i put data only in cells and can't add image to cell. and don't know how to make sections. This is my tree in firebase
Here is my model:
class Movie {
var movieName: String
var movieDuration: Int
var movieDescription: String
var movieGenre: String
var movieImage: String
init(movieName: String, movieDescription: String, movieDuration: Int, movieGenre: String, movieImage: String) {
self.movieName = movieName
self.movieDuration = movieDuration
self.movieDescription = movieDescription
self.movieGenre = movieGenre
self.movieImage = movieImage
}
}
and TableViewController code:
var ref: DatabaseReference?
var movies = [Movie]()
override func viewDidLoad() {
super.viewDidLoad()
ref = Database.database().reference().child("Monday")
ref?.observe(.childAdded){ [weak self](snapshot) in
let key = snapshot.key
guard let value = snapshot.value as? [String: Any] else {return}
if let movieDescription = value["description"] as? String, let movieDuration = value["duration"] as? Int, let movieGenre = value["genre"] as? String, let movieImage = value["image"] as? String {
let movie = Movie(movieName: key, movieDescription: movieDescription, movieDuration: movieDuration, movieGenre: movieGenre, movieImage: movieImage)
self?.movies.append(movie)
if let row = self?.movies.count {
let indexPath = IndexPath(row: row-1, section: 0)
self?.tableView.insertRows(at: [indexPath], with: .automatic)
}
}
}
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return movies.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let movie = movies[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "MovieCell", for: indexPath)
cell.textLabel?.text = movie.movieName
cell.textLabel?.textColor = .white
cell.detailTextLabel?.text = movie.movieGenre
cell.detailTextLabel?.textColor = .white
return cell
}
if someone can help me with this it will be great...)