2016-11-02 4 views
2

Warum bekomme ich einen Fehler, wenn ich diesen Code hinzufügen ?: , myProfileWorkoutTableViewCellDelegateFehler beim Hinzufügen von Zell Delegierten Klasse - rasche

Zu meiner Klasse ?:

class myProfileTableViewController: UITableViewController, UICollectionViewDataSource, UICollectionViewDelegate, myProfileWorkoutTableViewCellDelegate { 

Dies ist der Anfang meines myProfileTableViewCell.swift:

import UIKit 
import Firebase 
import FirebaseDatabase 

protocol myProfileWorkoutTableViewCellDelegate { 
    func watchTrainingPressed(cell: myProfileWorkoutTableViewCell) 
} 

class myProfileWorkoutTableViewCell: UITableViewCell { 

und dies ist meine Schaltfläche in der Zelle:

@IBAction func watchTrainingPressed(sender: AnyObject) { 
     if let _ = delegate { 
      delegate?.watchTrainingPressed(self) 
     } 
    } 
+0

Welche Fehler haben Sie bekommen? – dan

+0

@dan 'Typ 'myProfileTableViewController entspricht nicht dem Protokoll' myProfileWorkoutTableViewCellDelegate'' –

+0

Implementiert der Tabellenansicht-Controller die in Ihrem Protokoll deklarierte Funktion? – dan

Antwort

3

Sie benötigen die Funktion

func watchTrainingPressed(cell: myProfileWorkoutTableViewCell)

in Ihrem myProfileTableViewController Klasse zu implementieren.

+1

Doh! Mein schlechter Dank! –

1

Sie müssen sicherstellen, dass Sie myProfileWorkoutTableViewCellDelegate an der Spitze der Klasse myProfileTableViewController und alle nicht optionalen Funktionen hinzufügen.

class myProfileTableViewController:UIViewController, myProfileWorkoutTableViewCellDelegate { 

    // viewDidLoad etc.... 

    //MARK: - myProfileWorkoutTableViewCellDelegate 

    func watchTrainingPressed(cell: myProfileWorkoutTableViewCell) { 

      print("code goes here") 
    } 
} 

erwähnenswert, auch weil Ihre Stellvertretung ist optional delegate?. Sie brauchen nicht die if let _ = delegate { Check