2016-11-08 5 views
0

ich diesen FehlerWert vom Typ `UITableViewCell' har kein Mitglied` MyNote`

Wert vom Typ UITableViewCell hat kein Mitglied MyNote

auf dieser Zeilenleitung:

cell.NyNote = cell.textLabel?.text 

Weiß nicht, was ich tun soll, bitte hilf mir!

import UIKit 

class ViewController: UITableViewController { 

    let array = ["item1", "item2", "item3"] 

    override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    tableView.rowHeight = 70 
    tableView.backgroundView = UIImageView(image: UIImage(named: "concrete_seamless")) 
    } 
    // navigation bar animated 
    override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 

    navigationController?.navigationBar.alpha = 0.5 
    } 

    override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
    } 

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

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

    if(indexPath.item % 2 == 0){ 
     cell.backgroundColor = UIColor.clear 
    } 
    else{ 
     cell.backgroundColor = UIColor.white 
     UIColor.white.withAlphaComponent(0.2) 

     cell.textLabel?.backgroundColor = UIColor.white 
      UIColor.white.withAlphaComponent(0.0) 

    } 
    // text color 
    cell.textLabel?.textColor = UIColor.darkGray 

    cell.textLabel?.text = array[indexPath.item] 
    cell.NyNote = cell.textLabel?.text 
    return cell 
    } 

    func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    if (segue.identifier == "detailview") { 
     let cell = sender as! customcell 
     let detailview = segue.destination as! DetailViewController 
     detailview.preMyNotes = cell.NyNote 
    } 

    } 

} 

Und hier ist die var MyNotes:

import UIKit 

class customcell: UITableViewCell { 

    var NyNote:String? 

    override func awakeFromNib() { 
    super.awakeFromNib() 
    // Initialization code 
    } 

    override func setSelected(_ selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 

    // Configure the view for the selected state 
    } 

} 
+0

Ersetzen Sie einfach die „UITableViewCell“ mit „CustomCell“, wo Sie die Zelle definiert haben – Aditya

Antwort

0

Sie haben die Zelle zu der Unterklasse zu werfen, da sonst der Compiler nicht darüber weiß. Ändern Sie diese Zeile

let cell = tableView.dequeueReusableCell(withIdentifier: "customcell")! as UITableViewCell 

zu

let cell = tableView.dequeueReusableCell(withIdentifier: "customcell")! as customcell 
+0

Danke für mich gearbeitet! –

Verwandte Themen