Buka Cakrawala
Buka Cakrawala

Reputation: 189

Why is custom UITableViewCell not showing any property?

So I have a custom UITableVIewCell class:

class MovieTableViewCell: UITableViewCell {

   @IBOutlet weak var movieImageView: UIImageView!
   @IBOutlet weak var titleLabel: UILabel!
   @IBOutlet weak var dateLabel: UILabel!
   @IBOutlet weak var priceLabel: UILabel!

}

and return cell at TableViewController

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let tableViewCell: MovieTableViewCell = tableView.dequeueReusableCell(withIdentifier: "movieCell", for: indexPath) as! MovieTableViewCell

    tableViewCell.titleLabel.text = "Title"
    tableViewCell.priceLabel.text = "Price"

    return tableViewCell
}

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

I've assigned both delegate and datasource to self in the viewdidload, and also make sure that all reuseIdentifier and name class are exactly the same. But when I run it in the simulator, tableview doesn't return any label.

Basically I have an empty array called movies and perform a networking process in the viewDidLoad and append each object to movies. Here's my networking function.

func getAllMovies() {
    Alamofire.request("https://itunes.apple.com/us/rss/topmovies/limit=25/json").responseJSON { (response) in
        if let json = response.result.value as? [String: AnyObject] {
            let feed: [String: AnyObject] = json["feed"] as! [String: AnyObject]
            let entries = feed["entry"] as! NSArray

            for (index, entry) in entries.enumerated() {

                let movie = Movie()

                let dict = entry as! [String: AnyObject]

                if let link = dict["id"]?["label"] {
                    movie.itunesURL = link as! String
                }

                if let title = dict["im:name"]?["label"] {
                    movie.title = title as! String
                } else {
                    movie.title = "No Available"
                }

                if let price = dict["im:price"]?["label"] {
                    movie.price = price as! String
                } else {
                    movie.price = "$0.00"
                }

                if let date = dict["im:releaseDate"]?["label"] {
                    movie.releasedDate = date as! String
                }


                self.images = dict["im:image"] as! NSArray
                self.imgageAttribute = self.images[0] as! [String: AnyObject]

                if let imageURL = self.imgageAttribute["label"] {
                    movie.coverImageURL = imageURL as! String
                }

                self.movies.append(movie)
            }
        }
    }

}

Upvotes: 0

Views: 80

Answers (1)

Buka Cakrawala
Buka Cakrawala

Reputation: 189

add tableView.reloadData() after performing the networking request.

Upvotes: 1

Related Questions