class - How can I call this function? -


i stuck right now, have tried seams logical me make work having no luck...

i got in separate swift file:

import foundation import uikit

class myviewcontroller: uiviewcontroller {      func background() {         var imageview : uiimageview         imageview  = uiimageview(frame:cgrectmake(0, 0, 100, 300));         imageview.image = uiimage(named:"bg.jpg")         self.view.addsubview(imageview)     } } 

i want call separate view controller file. reason doing because can call background class in view controllers , don't have same code in each one.

the ways have tried calling are:

myviewcontroller.background() - error missing parameter #1 in call

background() - error use of unresolved identifier 'background'

myviewcontroller() - don't error nothing happens.

i appreciate if tell me how can call function 'viewdidload' part in view controller.

thank you.

you're barking wrong tree. if call background method in myviewcontroller, still not accomplish trying accomplish, because when call background in "separate view controller file", self in background method other view controller - , putting uiimageview other view controller's view, not this view controller's view. if want able same thing separately in each view controller, need make background method available internally in each of them.

the way inject background through extension into uiviewcontroller itself, view controllers inherit:

extension uiviewcontroller {     func background() {         var imageview = uiimageview(frame:cgrectmake(0, 0, 100, 300))         imageview.image = uiimage(named:"bg.jpg")         self.view.addsubview(imageview)     } } 

now any view controller in app can self.background() (or background()) call method.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -