2017-04-17 88 views
0

我希望通過「自我」,以便它可以設置爲委託。傳遞自己作爲參數設置爲委託

例如

func getBanerView(in view : UIView, self : parameterType)-> GADBannerView{ 
    view.addSubview(bannerView) 
    bannerView.adUnitID = "ca-app-pub-3940256099942544/6300978111" 
    bannerView.translatesAutoresizingMaskIntoConstraints = false; 
    ***bannerView.delegate = self*** 

    return bannerView 
} 

我如何實現這一目標?

感謝

+0

Pass參數類型'AnyObject' – Dhiru

+0

您還需要讓您的超類繼承您所使用的委託:'class ViewController:UIViewController,GADBannerViewDelegate'或其他... – LinusGeffarth

回答

3
func getBanerView(in view : UIView, delegate: GADBannerViewDelegate)-> GADBannerView { 

    view.addSubview(bannerView) 
    bannerView.adUnitID = "ca-app-pub-3940256099942544/6300978111" 
    bannerView.translatesAutoresizingMaskIntoConstraints = false; 
    bannerView.delegate = delegate 

    return bannerView 
} 

然後調用

getBanerView(*someView*, delegate: self) 

希望它能幫助。 :)