block传值

//block传值(view向controller中的view中传值,也可以是controller向controller中传值)

//view中
//typealias的作用是用左边代替右边
//(Int)->Void代表传递的值是Int型的,返回值是void
typealias pushCarouselblock = (Int)->Void
//定义一个传值的变量pPushCarouselblock
var pPushCarouselblock:pushCarouselblock?
//待传递的值是indexOfCurrentImage(Int型)
pPushCarouselblock!(indexOfCurrentImage)

//controller页面中
self.headerView.pPushCarouselblock = { locationIn in
    //在该视图的view中通过此方式用
    //locationIn代表indexOfCurrentImage


}

通常controller向view传值跳转时带过去

view向controller传值用block 

posted @ 2017-06-13 18:16  牛郑焜  Views(109)  Comments(0Edit  收藏  举报