我正在使用Facebook API登錄和註銷。如何在swift中創建UITableViewCell中的Facebook註銷按鈕
在我的初始視圖控制器中,我爲登錄添加了一個Facebook按鈕,它工作。
import UIKit
import FBSDKLoginKit
class SignInViewController: UIViewController, FBSDKLoginButtonDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let facebookLoginButton = FBSDKLoginButton()
view.addSubview(facebookLoginButton)
facebookLoginButton.frame = CGRect(x: 16, y: 50, width: view.frame.width - 32, height: 50)
facebookLoginButton.delegate = self
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
print("Log out!")
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if error != nil {
print(error)
}
print("Success!")
let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let desController = mainStoryboard.instantiateViewController(withIdentifier: "SWRevealViewController") as! SWRevealViewController
self.present(desController, animated: true, completion: nil)
}
}
這之後我創建了一個UITableViewController
的應用程序菜單 並在此菜單我創建了一個UITableViewCell
,並把一個按鈕。
import UIKit
import FBSDKLoginKit
class LogOutTableViewCell: UITableViewCell, FBSDKLoginButtonDelegate {
@IBOutlet weak var btnLogOut: UIButton!
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
}
@IBAction func btnLogOutAction(_ sender: UIButton) {
print("clicked!")
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
print("LogOut!")
}
}
我想在點擊此按鈕時註銷Facebook。
我有錯誤:Type LogOutTableViewCell does not conform to protocol FBSDKLoginButtonDelegate
有誰知道如何解決這個問題?還是有人知道另一個解決方案嗎?
我在哪裏添加它?我嘗試並收到另一個錯誤:'使用未解析的標識符loginButton(_:didCompleteWith:error:)' –
更新了我的答案@VictorMendes – ronatory
謝謝!我再也沒有錯誤了! –