Open abhinav2014 opened 4 years ago
There is now way for viewWillAppear will be called because, they are added as subviews. I have achieved similar behavior with protocols. https://github.com/subinspathilettu/SJSegmentedViewController/issues/143
Use the delegate method
func didMoveToPage(_ controller: UIViewController, segment: SJSegmentTab?, index: Int) { if index == 0 { NotificationCenter.default.post(name: Notification.Name("yourViewController"), object: nil) }else if index == 1 { NotificationCenter.default.post(name: Notification.Name("yourViewController"), object: [nil]) } }
Put this notification in your viewwillappear
NotificationCenter.default.addObserver(self, selector: #selector(updateCode), name: Notification.Name("yourViewController"), object: nil)
@objc func updateCode(notification: Notification) { //do what u need }
When i set segmentControllers = [viewController1, viewController2, viewController3] viewWillAppear is called for all the controllers at one time, i.e., all the controllers are loaded and shown at the same time, and not on selecting the tab. How can this be resolved that when i select a tab, then only viewWillAppear is called. Please help.