ios - Call class from other Swift File -


i have piece of code being used go 1 viewcontroller viewcontroller in different storyboard. now, since have lot of storyboards , viewcontrollers, wanted create different file manages navigation code. have problem code working navigation file in view controller files. hope can me this.

here code navigation:

class navigation{     func viewnavigation(){         var storyboardname:string         var controllername:string          let storyboard = uistoryboard(name: storyboardname, bundle: nil);         let controller =  storyboard.instantiateviewcontroller(withidentifier: controllername)  uiviewcontroller; present(controller, animated: false, completion: nil)      } } 

i have problem "present" code right, tip on helpful.

here code view controller:

import uikit  class geographicalfeeder: uiviewcontroller {     @iboutlet weak var gobackbutton: uibarbuttonitem!     @iboutlet weak var viewtitle: uinavigationitem!     @iboutlet weak var administratorbutton: uibarbuttonitem!      @iboutlet weak var composebutton: uibutton!      //navigation actions     @ibaction func tohomefeedervc(_ sender: any) {     } 

the code needs processed in ibaction can fill in destination storyboard , destination view controller.

your problem casting incorrectly. code:

let storyboard = uistoryboard(name: storyboardname, bundle: nil);         let controller =  storyboard.instantiateviewcontroller(withidentifier: controllername)  uiviewcontroller; present(controller, animated: false, completion: nil) 

you casting controller uiviewcontroller when must cast class of controller segueing to.

so replace uiviewcontroller viewcontroller name created:

storyboard.instantiateviewcontroller(withidentifier: controllername)  yourviewcontrollerclasshere 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -