2017-05-01 3 views
0

So habe ich eine benutzerdefinierte UITableViewCell Klasse:Warum zeigt benutzerdefinierte UITableViewCell keine Eigenschaft?

class MovieTableViewCell: UITableViewCell { 

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

} 

und Rück Zelle bei 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 
} 

ich beide delegate und datasource Selbst im viewDidLoad zugewiesen haben, und auch sicherstellen, dass alle reuseIdentifier und Name Klasse sind genau gleich. Aber wenn ich es im Simulator starte, gibt tableview kein Label zurück.

Grundsätzlich habe ich ein leeres Array namens movies und führen Sie einen Netzwerkprozess in der viewDidLoad und jedes Objekt an Filme anhängen. Hier ist meine Netzwerkfunktion.

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) 
      } 
     } 
    } 

} 
+0

Würde es Ihnen etwas ausmachen, die gesamte TableViewController-Klasse zu veröffentlichen? –

+1

bist du sicher, 'Filme' Array ist nicht leer? – Sulthan

+0

@Sultan nein sie sind nicht –

Antwort

1

hinzufügen tableView.reloadData() nach der Vernetzung Anfrage durchführen.

Verwandte Themen