SideMenu Jonkykong sideMenuDidAppear and sideMenuDidDisappear delegate not firing - ios

I'm trying to apply Jonkykong-SideMenu in my project with QR scanner and the Pulley library as well, the result is fine, the SideMenu could slide in and slide out, but I couldn't get the delegate for sideMenuDidAppear and sideMenuDidDisappear to fire. I need those to start and stop the capture session.
My Storyboard:
In my ProductScanPageViewController (Main View Controller), I put the extension below:
extension ProductScanPageViewController: SideMenuNavigationControllerDelegate {
func sideMenuDidAppear(menu: SideMenuNavigationController, animated: Bool) {
print("sidemenudidappear")
stopCaptureSession()
}
func sideMenuDidDisappear(menu: SideMenuNavigationController, animated: Bool) {
startCaptureSession()
}
}
and the print result didn’t appear in the console when I slide out the SideMenu. Do I have to put the SideMenu in the PulleyViewController instead? The initial ViewController in the storyboard is already used by Pulley.
I might modify one of the frameworks as last resort, but I'm trying to avoid that, any help?

Setting sideMenuNavigationController.sideMenuDelegate = self after preparing for segue solves the problem

Related

When navigating back in navigation controller view doesn't load

I have weird situation and have no clue how to debug it. I load three viewControllers in navigation controller. When Im navigating back from there second and first ViewController doesn't display anything just white screen I added print methods everywhere in lifecycle methods and it seems that it loads views but anyway they not visible. What could be the problem?
Yep It's weird, There maybe some code which do something with your view on such events like:
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
// remove some subviews or change constraints.
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// remove some subviews or change constraints.
}
Please send us a code of the view controller which has the problems and code how exactly you show the controller.

Can SwipeGesture (Present Modely/Show/Show Details/Deprecated Push) can only handle a maximum of 4 View controllers?

In my App I am using 5 ViewControllers. While I try to navigate to last one , It won't display. No error message displayed.
To go to next screen We are giving action to left swipe gesture using segue.
We have tried the solution provided in below link. They said to use push deprecated and then compile. Again use show segue(not specified Show / Show Details) we tried using both and the compile. It will solve the problem as it is issue with Xcode. But this solution doesn't work. I also not able to comment on their post.
Can UINavigationController only handle a maximum of 4 Viewcontrollers?
We have tried all navigation using segue Show, Show Details,Present Modally and
Push Deprecated.
In all segue except Push Deprecated controller neither go to fifth controller neither it give error. Push deprecated gives sigbart error while tried to run on iPhone.
We are using Xcode10 and iOS 12.0.
While developing same app in Xcode 9 Objective C code we have first 2 navigation are present modally, next two are having show segue and last one is present modally. It works fine on that code. We tried this solution also but it wont work. Currently I am upgrading same code in Swift with latest library and i am facing this issue. Please help.
There is no limit in number of pushed view controllers. Maybe it would be easier to add gesture recognizer in code on viewDidLoad for instance and put some breakpoints to see what goes on there.
To play around with these things you can try this minimalistic code which will push a new view controller on every tap. You can create a new project and simply overwrite the content of autogenerated ViewController and all should work:
import UIKit
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
present(UINavigationController(rootViewController: MyViewController()), animated: true, completion: nil)
}
}
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(onTap)))
self.title = "View controller \(navigationController?.viewControllers.count ?? 0)"
}
#objc private func onTap() {
navigationController?.pushViewController(MyViewController(), animated: true)
}
}
To explain:
An instance of ViewController will be created as a root view controller in your main window which is part of project settings (which storyboard to use) and part of autogenerated storyboard named main.
We need to wait for view to appear of the first view controller before we can present our new navigation view controller. We presented with having a root view controller as our own subclass of view controller called MyViewController. This view controller is not in storyboard.
When an instance of MyViewController comes into hierarchy (using push or present) a viewDidLoad will be called which creates a tap gesture recognizer set to a method to push a new instance of MyViewController. We also set a title depending on the number of view controllers on navigation controller just to have more information.
As said this is a minimalistic code. But in general you would do something like:
override func viewDidLoad() {
super.viewDidLoad()
view.addGestureRecognizer({
let swipeRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(onSwipeLeft))
swipeRecognizer.direction = .left
return swipeRecognizer
}())
}
#objc private func onSwipeLeft() {
let controllerToBePushed = UIStoryboard(name: "my_storyboard_name", bundle: nil).instantiateViewController(withIdentifier: "the_identifier_I_set_in_storyboard") as! WhateverTheTypeOfMyViewControllerIs
navigationController?.pushViewController(controllerToBePushed, animated: true)
}

Swift 3: Do I need to link the viewDidAppear function in storyboard?

I am a beginner in Swift. I am trying to make a basic login and account creation system in a single-view Swift 3 project.
In my ViewController.swift, I have a viewDidAppear function:
override func viewDidAppear(_ animated: Bool) {
self.performSegue(withIdentifier: "loginView", sender: self)
}
Here is my main storyboard:
Main.storyboard
Upon opening the app, I want the "protected data" page to open first, then check if user has logged in. If not, the login page should appear. However, I don't know how to achieve this. I tried to link navigation controller, but I don't see the function as an option.
Right now, when I run the simulator, only the "protected data" page shows.
What do I do? In addition, is there anything wrong with my viewDidAppear function?
If you really want this navigation flow
Upon opening the app, I want the "protected data" page to open first, then check if user has logged in.
then you should organise your ViewController.swift like this
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if /* userDidLogin... REPLACE WITH YOUR CODE*/ {
performSegue(withIdentifier: "ShowLogin", sender: nil)
}
}
}
Of course you also need to:
open Storyboard
select the segue that connect ViewController to the login view controller
assign to it the name ShowLogin
Make sure "Inherit From Target" is checked.

UITableViewDelegate not called

I'm having a weird behaviour here. I have a UITableView inside a UIViewController that is contained in a UITabBarController.
It's working fine all the time, except when I receive a notification from iMessage and open it. Then if I go back to the app using the top left < MyApp, then the UITableView delegate (more specifically the didSelectRow method) is not called anymore but I'm still able to scroll it.
If I receive notifications from other apps (like Duolingo and Inbox), open it and go back to app, it works fine, except with iMessage.
Has this happened to anyone here before?
I'm using Swift 3 and Xcode 8.1.
Thanks
UPDATE
Here are some methods:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Here i'm just updating the navigation bar color
if let navBar = self.navigationController?.navigationBar as? NavigationBar {
navBar.apply(color: colorRGB(33, 163, 161))
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Just making navbar trasnparent
if let navBar = self.navigationController?.navigationBar as? NavigationBar {
navBar.applyTransparency()
}
}
The table view is created in the storyboard and data source and delegate is assigned there too.

Calling segue programmatically not working

I am trying to make a splash screen. I have a view that has a background image being drawn onto it and then another view I want to transition to after a few seconds. I am trying to use the following code:
self.performSegueWithIdentifier("showApp", sender: self)
I created a segue between the two views by ctrl+dragging a line from one to the other. I set the segue's identifier to "showApp".
When I run the code nothing happens and there are no errors. Any ideas?
Here is the controller for the splash screen:
class SplashViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
sleep(2)
// THIS DOES NOTHING:
self.performSegueWithIdentifier("showApp", sender: self)
// THIS AS SUGGESTED ALSO DOES NOTHING:
var otherViewController:UIViewController = self.storyboard.instantiateViewControllerWithIdentifier("test") as UIViewController
self.presentViewController(otherViewController, animated: true, completion: nil)
}
}
Normally, you need a navigation controller in order to use segue.
Highlight your SplashViewController object inside the Storyboard and go to
Editor -> Embeded In -> Navigation Controller
After that, remove the code suggested by Clement and try running the project again, you should get the result that you expected.

Resources