AppDelegateで代理関数を呼び出そうとしていますが、呼び出されないようです。AppDelegateから代理関数を呼び出せません
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,appdelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if let navigationController = window?.rootViewController, let
viewController = navigationController.childViewControllers.first as? ViewController {
viewController.delegate = self
}
// Override point for customization after application launch.
return true
}
func callfromDelegte(indicator: UIActivityIndicatorView) {
indicator.stopAnimating()
}
ViewController-:
import UIKit
protocol appdelegate:class {
func callfromDelegte(indicator:UIActivityIndicatorView)
}
class ViewController: UIViewController {
@IBOutlet weak var indicator: UIActivityIndicatorView!
weak var delegate:appdelegate?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
indicator.startAnimating()
indicator.hidesWhenStopped = true
}
@IBAction func rotateAction(_ sender: UIButton) {
if delegate != nil{
delegate?.callfromDelegte(indicator: indicator)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
デリゲートは常にnilであるが、それは関数内で行くことはありません。何が私はまだ 代議員についてはありませんか? GoogleはどのようにしてGIDSignInDelegateとその代理関数をコントローラクラスからAppDelegate内で呼び出すのですか?私はそれが非常にばかな質問かもしれないことを知っていますが、私はまだ知りたいです。ありがとう
私はnavigationControllerで私のコントローラを埋め込んでいないので、それは働いた。それでとすれば、に入っていなかった。それはthis-のように単純に働いた:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// if let navigationController = window?.rootViewController, let
// viewController = navigationController.childViewControllers.first as? ViewController {
// viewController.delegate = self
// }
// Override point for customization after application launch.
let controller = window?.rootViewController as! ViewController
controller.delegate = self
return true
}
まだスウィフトある
役立つことを願っています。 –
@ TusharSharma、私はデリゲートの値を見ることができ、それは私のために無しではありません –
ViewControllerクラスはどこにあなたのストーリーボードの中で定義しましたか? Main.storyboardの中にありますか? –