Hide menu bar in ECSlidingViewController in an option in swift - swift

I am using ECSlidingViewController for the menu navigation. I have a option logout on which on selection logout the user. When the user login agin the menu bar will be visible instead of hidden. Swift code to hide the menu bar on logout selection.
import Foundation
import UIKit
import Parse
class MenuTableViewController: UITableViewController {
#IBAction func unwindToMenuViewController(segue: UIStoryboardSegue) {
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 4 {
PFUser.logOut()
var loadLoginPage: UINavigationController = self.storyboard?.instantiateViewControllerWithIdentifier("LoginNavigationController")! as UINavigationController
self.presentViewController(loadLoginPage, animated: false, completion: nil)
}
}
}

Try self.slidingViewController?.resetTopViewAnimated(true). Then it's just a matter of removing the pan gesture recognizer of the ECSlidingViewController from the current top view and disabling any buttons that might open the menu.

var slidingViewController: ECSlidingViewController = self.view.window?.rootViewController as! ECSlidingViewController
slidingViewController.resetTopViewAnimated(true)

Related

View Controller shows as pop-up

I want a normal segue, so no pop-up. But when I push the button to go to the next ViewController, it shows as ab pop-up. The buttons to the next ViewController is in a different storyboard than the ViewController I'd like to go to.
This is the code of the first ViewController:
import UIKit
//some other code
class LoginViewController: UIViewController {
//some other code
override func viewDidLoad() {
super.viewDidLoad()
//some other code
}
#objc private func ProceedTapped(){
//Door naar storyboard van de daadwerkelijke app
print("Proceed clicked")
performSegue(withIdentifier: "goToAppIdentifier", sender: self)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
}
And this is the code of the ViewController I'd like to go to:
import UIKit
class HomeScreen: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("Home has loaded")
}
}
The kind of the segue of the "Storyboard Segue" is "Show (e. g. push)"
You just have to go to story board select the 2nd view controller and change presentation style to "Full Screen". Please check below image for reference

How can I go back to the previous ViewController from UICollectionViewCell?

There are two pages(view controllers) in Main.storyboard: FirstViewController and SecondViewController. I have added a button into FirstViewController. Here is the button click scope:
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MainPage") as! SecondViewController
controller.modalPresentationStyle = .fullScreen
show(controller, sender: nil)
I have added UICollectionView into SecondViewController. UICollectionViewCell is also added (with .xib file) I have added back button in to .xib file. And I wanted to write below code for back button action(please focus func btnBack)
import UIKit
class ViewCell: UICollectionViewCell {
#IBOutlet weak var lblOutlet: UILabel!
#IBOutlet weak var contentViewOutlet: UIView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
#IBAction func btnBack(_ sender: UIButton) {
present(controller, animated: true, completion: nil)
}
}
but as you known, ViewCell has no member dismiss. What i am trying to do is going back to the FirstViewController with this back button in UICollectionViewCell. And yes, app user see this back button in each ui collection records.
May be you can use protocol & delegate pattern to pop back from second view controller. You can add in your CollectionViewCell file a protocol like
protocol popBackDelegate {
func popBack()
}
then inject it in your CollectionViewCell
var popBackDelegate: popBackDelegate!
After that you can call it in your btnBack action
popBackDelegate.popBack()
Now you have to bind it your second view controller's collection view's cellforitem event
cell.popBackDelegate = self
Lastly you can conform this protocol func in your view controller and pop back in that.
Hopefully I helped you with that.
I would suggest add a callback in ViewCell for such small interaction as below,
class ViewCell: UICollectionViewCell {
#IBOutlet weak var lblOutlet: UILabel!
#IBOutlet weak var contentViewOutlet: UIView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
public var dismiss: (()-> Void)? = nil
#IBAction func btnBack(_ sender: UIButton) {
self.dismiss?()
}
}
Now, in your ViewController bind that callback inside cellForItemAt as,
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: ViewCell = // Your code to dequeue cell
cell.dismiss = { [weak self] in
self?.dismiss(animated: true, completion: nil) // OR Pop whatever
}
}

TableView disappears after segue unwind

I've spent the whole day trying to figure this out, would like some insight into what's happening here:
I have a custom UITableViewController that's embedded in a navigation controller, and it has a button that triggers a segue to a plain UIViewController.
The plain UIViewController has a button that unwinds to the TableViewController, as well as a "back" button that's given for free thanks to navigation controller.
Now the issue: When I segue from TableViewController to UIViewController, everything works. From UIViewController, if I press the "back" button, it winds back and the TableView is reloaded automatically. HOWEVER, when I press the button that is linked to #IBAction to unwind, it unwinds to the TableViewController but nothing shows up, not even an empty table.
My debug view showed that once I tried to unwind using my button (not "back), TableViewController came back on screen but its frame was super small and nothing was in it, so the black background of the navigation controller was showing, thus just a black screen where the table should be.
Can anyone tell me how to manually reinitialize the tableView or reset the TableViewController when I unwind? I tried tableView.reload() in viewDidAppear() and nothing happened, as I suspect the problem is the TableViewController itself not having the original frame as before segueing.
Link to screenshots with descriptions
TableViewController code:
class StatsTableViewController: UITableViewController {
//variable stuff
#IBAction func unwindToRoot(_ sender: UIStoryboardSegue) {
}
override func viewDidLoad() {
super.viewDidLoad()
self.getData()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
DispatchQueue.main.async {
self.tableView.reloadData()
}
self.getData()
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return solves.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! StatsTableViewCell
cell.timeLabel?.text = solves[indexPath.row].0
cell.scrambleLabel?.text = solves[indexPath.row].1
return cell
}
//other stuff
}
Set Delegate Datasource Methods
//Add this two lines in viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
self.getData()
//Add this line
self.UITableViewName.delegate = self
self.UITableViewName.dataSource = self
}
You are using this two methods in statusTableViewController
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "SelectionSegue" {
//Your code
}
}
#IBAction func unwindToThisView(sender: UIStoryboardSegue) {
// set Delegate datasource method
}
set outlet for unwindToThisView button to see the images
1.Click exit button for last ViewController
see Presenting Segues outlet for the Back Button
set action for back button

Opening a side menu on click on a TAB bar in SWIFT

I want to make something like below snapshots.
When I click on profile tab bar instead of opening a new view controller it shows a side menu. Is it something that has been handled on click of tabbar ?
if you want to achieve something like your screenShot then you are using a wrong library, because when you show your right viewController the front viewController go to left by amount of width of your right viewController, but anyways here is the code for what you need to do
first you need to put your viewController as delegate of your TabBarViewController and in func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool you need to return false and call the method of SWRevealViewController to show right viewController rightRevealToggleAnimated(true)
class FirstViewController: UIViewController,SWRevealViewControllerDelegate,UITabBarControllerDelegate {
#IBOutlet weak var sliderControl: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.revealViewController().delegate = self
self.tabBarController?.delegate = self
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
//self.view.removeGestureRecognizer(self.revealViewController().panGestureRecognizer())
//self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {
//checking for specific viewController
if(viewController is DesiredViewControllerClass) {
self.revealViewController().rightRevealToggleAnimated(true)
}
return false
}
}
I hope this helps you, regards
You can use the tab bar delegate:
extension ViewController: UITabBarDelegate {
func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
// Present hamburger menu
}
}

how to create xib subview at the center of tableview swift

I have tableview and I created the custom xib uiview as "detailview" for it. I want to show this detailview at the center of scrolled area when tapped to tableview cell. I can show this view but cannot centralized it. when I set value to frame manually, subview will be at center (approximately) but when I tap the cell which is at the bottom, the subview is appearing at the top of page and also it is moving when i scroll the tableview.
Please help me to show this view at the center of the scrolled area and be fixed
Here is my codes;
Detail View :
class TopTenDetailView: UIView {
var screenWidth:CGFloat = UIScreen.mainScreen().bounds.width*0.08
var screenHeight :CGFloat = UIScreen.mainScreen().bounds.height*0.08
class func instanceFromNib() -> UIView {
return UINib(nibName: "TopTenDetail", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as! UIView
}
override func awakeFromNib() {
super.awakeFromNib()
self.layer.cornerRadius=10
let testFrame : CGRect = CGRectMake(screenWidth,screenHeight,320,480)
self.frame = testFrame
self.userInteractionEnabled=true
}
#IBAction func close(sender: UIButton) {
self.hidden=true
}
}
And TableViewController's method ;
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var detailView = TopTenDetailView.instanceFromNib
self.view.addSubview(detailView())
}
The way this is setup has many problems and i would be surprised if it actually ever works as intended.
A much better, simpler setup uses a OverFullScreen presentation style and it goes like this:
Create a separate UIViewController for your detail view, let's call it DetailViewController use Interface Builder. Make sure to set the background color to CLEAR
Wire up a segue from the "base" UIViewController that holds your UITableView to DetailViewController and give the segue a name. Let's call it 'detailSegue' , basically drag from one view controller to the other. Make sure that you are not dragging from the view but from the yellow icon at the top of the view controller. You are done in Interface Builder.
Ok, now for the code:
// MARK : - UITableViewDelegate
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("detailSegue", sender: self)
}
// MARK: - segues
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let vc = segue.destinationViewController as? UIViewController{
vc.modalPresentationStyle = .OverFullScreen
}
}
The OverFullScreen presentation style uses a proper UIViewController modal segue but leaves the presenting UIViewController visible under the presented one.
You can then just layout whatever you want on DetailViewController using Interface Builder and autolayout without having to do hacky match calculations on the layout at runtime.
Hope it helps!