UITableViewDelegate not called - ios

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.

Related

Wrong alignment of navigation bar button for second view controller in iOS 13

I am adding a button using the storyboard as below screenshot:
While presenting from 1st controller to 2nd controller, navigation bar button alignment is not displaying properly.
I don't know whether it's iOS 13 problem or what.
To fix this issue, you need to call setNeedLayout manually in the viewWillAppear method as mentioned below:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 13.0, *) {
navigationController?.navigationBar.setNeedsLayout()
}
}

SideMenu Jonkykong sideMenuDidAppear and sideMenuDidDisappear delegate not firing

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

Navigation Controller & TableView: NavBar Hidden after hidden = true one time

I have a UITableView embedded in a NavigationController. The cells each link out to a larger information ViewController. For UI purposes, I hide the Navigation Bar on the TableView and show it in the InfoViewController.
The problem I am experiencing is this: upon booting the app, the NavBar is successfully hidden on the TableView. The first time I tap into a cell and open an InfoViewController, the NavBar comes back as expected. I back out of that VC and into the TableView. Again, the NavBar is hidden, as expected. If I tap into another cell, the NavBar is not displayed as expected. NOTE: This happens even when I remove any code to hide the Navigation Bar.
Here are the relevant code snippets:
TableViewController (in ViewDidLoad()):
self.navigationController?.isNavigationBarHidden = true
InfoViewController:
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.isHidden = false
super.viewWillAppear(animated)
}
Why would it work the first time, but not the second. Any help is appreciated!
For clarification:
App opens to TableView:
enter image description here
I click into the TableViewCell to Segue to InfoViewController:
enter image description here
I hit "Back" to go back to TableViewController. NavBar is still hidden. I click on the same cell:
enter image description here
EDITED: Messed up the TableViewController Code. Put = false instead of = true.
Also, I have one more thought, please someone check this for me. The TableViewController is inside a UIContainerView. It is almost as if when I hit "Back" I am exiting the NavigationController flow and I cannot get back in it.
Please try this code its working fine for hiding navigationBar
TableViewController
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = true
}
}
InfoViewController
class InfoViewController : UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.isNavigationBarHidden = false
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.isNavigationBarHidden = true
}
}
Simple hide navigationbar again when the view controller is appear again,
do below code in tableViewController:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.isNavigationBarHidden = true
}

Weird bug when presenting a view controller

I have a basic app with a UITabBarController as the root view controller. When a user of the app is not signed in I'm showing a modal controller via window!.rootViewController!.present(viewController, animated: true) in my AppDelegate. This works fine on all iPhone models, however the following happens on any iPad:
The background color of the SignInController is visible during the transition. Now comes the weird thing: When I change the view in Interface Builder to an iPad the bug is gone like so:
Changing the background color back to the transparent default removes at least the white background, however the view is still animating from the left bottom which is something I don't want. And by the way, changing the view in Interface Builder breaks the animation on all iPhones. Changing it back fixes it but breaks again all iPads.
This is the code (using ReSwift for state management):
func newState(state: State) {
switch (previousState.session, state.session) {
case (.loading, .notSignedIn), (.signedIn, .loading):
(window!.rootViewController! as! UITabBarController).selectedIndex = 0
let viewController = storyboard.instantiateViewController(withIdentifier: "SignInViewController")
window!.rootViewController!.present(viewController, animated: true, completion: nil)
default:
// more stuff
break
}
}
EDIT: Added the actual code.
I fixed it! 😊
The problem was a combination of having an observer on keyboardWillShowNotification and a becomeFirstResponder in the viewWillAppear method of the presented controller.
Moving the becomeFirstResponder into viewDidAppear fixed all the problems!
Thanks man! Saved my day.. I'm presenting the keyboard from within a tableview cell - I fixed it like this:
private var canPresentKeyboard: Bool = false
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
canPresentKeyboard = true
if _currentlySelectedIdType != .image {
reload(section: .idType)
}
}
func configure(cell: NumberIdTableViewCellInput) {
cell.set(delegate: self)
if canPresentKeyboard {
cell.clearAndSetFirstResponder()
}
}
I know the code is a bit out of context, but I believe the intention is clear.

iOS Navigation Bar Title set dinamically is making a ellipsis in text when view appears

I was trying to set the back button title in a navigation bar, like this
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.title = self.backUpTitle
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
self.title = "Back"
}
Where self.backUpTitle has the original title for the current ViewController.
It works very well, but I'm a having a quick effect each time I click "Back": the title of the navigation bar appears with the first three letters followed by ellipsis (Eg: "Title" would show as "Tit..."), and after the view fully appears, it shows the entire title without any problem.
The thing is... it does not happen in a normal case, so I guess it has to do with my solution about setting Back Button Title.
The question is: is there a way to avoid this effect? Am I calling self.title in a wrong function?
I’m using Xcode 8 and iOS 10.0
I’ve tried running your code on my own machine and I’m not showing the same problem; I’m thinking you might be using custom views for the title of the navigation bar and your self.backUpTitle is inside a custom view that causes the ellipsis.
Some suggestions:
If you just want to show “Create User” that way without the ellipsis, you might want to remove all custom views for your navigation bar and just set the ViewController title like what you are doing in your code.
Using “self.title” will change the title of your ViewController, make sure your ViewController is embedded to a UIViewController. However, if you created your navigation bar, setting the title should be:
navigationBar.topItem.title = “Create User”
Just to reiterate, this is what my code looks like (which looks like yours) under a ViewController that is embedded in a UINavigationController:
var backUpTitle: String!
override func viewDidLoad() {
backUpTitle = "Create User"
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.title = self.backUpTitle
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.title = "Back"
}

Resources