Changing navigation Left Bar button title while selecting collection cell inside a container view
Create the protocol method for view controller which contains collection view.
Inside HomeFilterVC
protocol HomeFilterVCDelegate: class {
func collectionViewDidTapped()
}
Then, declare delegate variable like as follow, which will assign to your view controller which contains UIContainerView
.
class HomeFilterVC: UIViewController {
weak var delegate : HomeFilterVCDelegate?
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let selfDelegate = self.delegate {
selfDelegate.collectionViewDidTapped()
}
}
}
Implement prepare(for segue:, sender:)
and HomeFilterVCDelegate
methods in HomeVC
and update your code as follow.
HomeVC:
class HomeVC: UIViewController {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "HomeFilterVC" {
let collectionVC = segue.destination as! HomeFilterVC
collectionVC.delegate = self
}
}
}
extension HomeVC: HomeFilterVCDelegate {
func collectionViewDidTapped() {
navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "cancel-music")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(self.closeViewTapped)).
}
}
I hope this will fix your issue.
how to open 'LGSideMenuController' side menu open from all viewcontroller?
You can use the same method to open "LGSideMenuController" as you did in "HomeViewcontroller".
Suppose in another viewcontroller, you want to open "LGSideMenuController" on click of button event then code will look like
@IBAction func openSideMenu(_ sender: Any) {
self.sideMenuController?.showLeftView(animated: true, completionHandler: nil)
}
Edit Answer
I checked your code and found that you are trying to present another viewcontroller screen over "LGSideMenuController" instead of using push transition.
Please change your code in SideMenuVC controller as below
@IBAction func eventsAction(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "EventsVC") as! EventsVC
//let navigationController = UINavigationController(rootViewController: vc)
//self.present(navigationController, animated: true, completion: nil)
self.sideMenuController?.hideLeftViewAnimated()
self.sideMenuController?.rootViewController?.show(vc, sender: self)
}
In the above code, i hide the sidemenu first and then push "EventsVC" view controller in sideMenuController. Please apply the same code on other button actions.
Hope it helps.
How to check if an array index exists or not in javascript?
Use typeof arrayName[index] === 'undefined'
i.e.
if(typeof arrayName[index] === 'undefined') {
// does not exist
}
else {
// does exist
}
Related Topics
iOS 8 Swift Audio Playback Execute Method on Completion
Linking Error When Building Parse in Xcode 7
Updated Approach to Reauthenticate a User
"Ambiguous Use of 'Children'" When Trying to Use Nstreecontroller.Arrangedobjects in Swift 3.0
Xctest Unit Test Data Response Not Set in Test After Viewdidload
Use of or Operator on Cloudkit Predicate
Including Zeros in Front of an Integer
After Getting Image from Uiimagepickercontroller, Uiimageview Rotates Image for iPhone 5
Is There Difference Between Using a Constructor and Using .Init
Swift Cannot Output When Using Nstimer
Swift: Ambiguous Reference to Member 'Map'
How to Decrease a Value Using Fieldvalue in Firestore (Swift)
Differences Between Ways of Initializing a Dictionary
Requestaccessformediatype Doesn't Ask for Permission
Using Reflection to Set Object Properties Without Using Setvalue Forkey