How to reuse view controllers in UITabBarController in storyboard mode with fast

I am using a UITabBarController with 3 subtasks that have the same structure, only different data or filters applied to the data. So far, I just made 3 subtitles and connected them, but I repeat myself, and I know that this may not be the right way to do something.

My question is how to create 1 under view with all its functions and presentation, and then reuse it only when using the correct filters. eg.

click on the "all data" tab> load the view using var filter = 'all' and var order_by = 'created_date'

click on the “filled tab”> load the view using var filter = 'completed' and var order_by = 'completed_date'

I think I can do something when I cook sega?

+4
source share
2 answers

Although there is not much context in your original post, I think it might work ...

You can set a global variable in the main subtitle, which you would like to configure in the content based on what I understood.

var customizationObject = CustomFilters()

and for CustomFilters do something like:

class CustomFilters {
 var filter1: String?
 var filter2: String?
//and so on
}

and in the prepareForSegue command, you pass the object to the destination view controller to set the filters.

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "Load View") {
        // pass data to next view
    }
}

, viewWillAppear viewDidLoad ( ), , .

+1

, , ctrl .

:

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    (self.viewControllers![0] as! DailyChartsViewController).title="Daily"
    (self.viewControllers![0] as! DailyChartsViewController).tabBarItem.image=UIImage(named: "daily")
    (self.viewControllers![0] as! DailyChartsViewController).filter = 1
    (self.viewControllers![1] as! DailyChartsViewController).title="Weekly"
    (self.viewControllers![1] as! DailyChartsViewController).tabBarItem.image=UIImage(named: "weekly")
    (self.viewControllers![1] as! DailyChartsViewController).filter = 7
}
+1

Source: https://habr.com/ru/post/1624226/


All Articles