将self作为要设置为委托的参数传递

时间:2017-04-17 08:23:18

标签: ios swift

我希望通过" self",以便可以将其设置为委托。

例如

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
}

我如何实现这一目标?

由于

1 个答案:

答案 0 :(得分: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)

希望有所帮助。 :)