using IBOutlet from another class in swift -


i have iboutlet in viewcontroller.swift called backgroundview

class viewcontroller: uiviewcontroller, sidebardelegate {      @iboutlet weak var backgroundview: uiview! 

and want use iboutlet on sidebar.swift

@objc protocol sidebardelegate{     func sidebardidselectbuttonatindex(index:int)     optional func sidebarwillclose()     optional func sidebarwillopen() }  //when item of sidebar selected, , when sidebar open or close class sidebar: nsobject, sidebartableviewcontrollerdelegate {     func handleswipe(recognizer:uiswipegesturerecognizer){         let bgv = viewcontroller()         if recognizer.direction == uiswipegesturerecognizerdirection.right {             showsidebar(false)             delegate?.sidebarwillclose?()             let blureffect = uiblureffect(style: uiblureffectstyle.light)             let blurview = uivisualeffectview(effect: blureffect)             blurview.frame = bgv.backgroundview.bounds             bgv.backgroundview.addsubview(blurview)          } else {             showsidebar(true)             delegate?.sidebarwillopen?()         }     } 

but when showing side bar, background doesn't blur. wrong?

you're not accessing view controller's instance. create new 1 , assign bgv, , modify one.

you access through delegate not creating new view controller. you'd have add variable protocol.

a better idea move stuff view controller should handle class instead of trying access views of controller. totally defeats purpose of delegation.

let blureffect = uiblureffect(style: uiblureffectstyle.light) let blurview = uivisualeffectview(effect: blureffect) blurview.frame = backgroundview.bounds backgroundview.addsubview(blurview) 

all code should go in sidebarwillclose in delegate (the view controller's implementation of method)

i'd recommend not making functions optional, you're going want parent controller able things when menu opens , closes. plus cleans code bit, fewer ?'s


Comments