SwiftSpinner not working on UIViewController. - swift

Ok, so I am using this project: https://github.com/icanzilb/SwiftSpinner
I downloaded the project and took the Swiftspinner.Swift file from the directory and added it to my project.
Now, When I add in a test like so:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
SwiftSpinner.show("Test")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Nothings happens when I run it. no errors it just says build succeeded and then opens in the simulator.
However, If I change the class delegation at the top to this:
class ViewController: UINavigationController {
I works, Can anyone fathom this out?

Move the call to viewDidAppear(_:).
The problem is that ViewController is more than likely the initial view that is created when you created the project. viewDidLoad() is called when .view is called on your controller. Since this is the initial view controller it has not yet been added to the key window. As a result the spinner adds itself to the key window then ViewController is added to key window covering up the spinner. If you used the view hierarchy debugger you will be able to see this happen. Once the root view is set this would no longer be an issue but it is still best practice to modify the UI after the view has appeared.

Related

I have a new UIViewController and new class, but I can't associate the two in Xcode 10

I've added a new View Controller to my storyboard. I've added a new Cocoa Touch Class .swift file and subclassed UIViewController. I select the new UIViewController in the storyboard and click the identify panel, but my new subclass OptionViewController doesn't show up in the dropdown.
I've done a Clean Build Folder. I've done a successful BUILD. Still no love.
class OptionsViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
etc.
Corruption. Exited Xcode and restarted it.

deinit not called on boilerplate macOS app

I've created new app from macOS Cocoa App template. The only change I've made is added deinit in NSViewController. So now it looks like this(complete code):
import Cocoa
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
func doSomething()
{
var a = 10
a = a + 1
print(a)
}
deinit {
doSomething()
print("deinit called")
}
}
Why I don't see deinit call? I've searched number of questions here, but couldn't find answer, as I don't have any retain cycle.
As Tobi says in his answer, deinit gets called right before an object is deallocated.
An object gets deallocated when there are no longer any strong references to it. (Nobody owns the object any more.)
In order to answer your specific question you need to look at how your view controller is created an who owns it.
I haven't done much Mac development in a while, so I'm kinda rusty on view controller lifecycle, but here's my recollection of how it works:
If you only have one app window, it is the view controller's owner, and the window never gets closed, that means the view controller will never get deallocated.
If you quit the app I don't think the system tears down your window hierarchy before terminating the app (unless you're app is a document-based app, in which case the app will be told to close all of it's document windows before quitting.)
A deinitializer is called immediately before a class instance is
deallocated.
Altho your question is not clear to me.
But the usual reason for failure to trigger deinit when expected is that you have a retain cycle that prevents your view controller from going out of existence.
Sometimes the reason is that your expectation that the view controller would be destroyed under the circumstances is incorrect.
But assuming it is correct, a retain cycle is the reason.
another suggestion is to use Hierarchies Debug.
answer those questions for your self.
is this the root UIViewController ?
is it dismissed properly ?

UIButton disappears after succesfull build

I am facing problem with my new app. I have developed many apps, but this problem i have for the first time. For testing my app I am using Apple iPad Mini 4.
I have a new, empty project. I have added only one UIButton. But when I build this project, succesfull build, and the app is running, after 2 seconds the UIButton disappears. When I use iPad or iPhone simulator, the button is there forever. No error appears, so i really do not know, what is going on. Anybody with similar problem?
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func example(_ sender: UIButton) {
print("Hello")
}
}
I have tried the same thing but working fine....no issues.
What you are saying is not possible It's not possible that way.
It's only possible if you put your button somewhere in LaunchScreen.
If you put you button on launch screen you can still add action to ViewController but you can't add outlet.
Verify this thing and let me know.

How to redirect a user to a login page if they are not logged in? Swift 3

I'm fairly new to the whole Swift thing, but I'm trying to make a simple login screen where if the user is not logged in, it redirects them to a login page. I seem to have something not write in the code as when I click on the tab to take me to the login page as I'm not logged in nothing comes Up? When I type in the code, Xcode says everything is fine but I've named the root loginView and everything seems to be alright, but when I load it nothing happens it just come up with the page as If you were logged in.
Any ideas?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool)
{
self.performSegue(withIdentifier: "loginView", sender: self);
}
}
As you do not get any errors I believe you've correctly named your segue right? if that's the case. Please make sure you're doing as following:
Let's assume you have 2 View Controllers one is the main page that logged in users can go (we name it LandingVC) and the other one is the login view controller (we call it LoginVC).
First thing to check: make sure you're writing the code in LandingVC ?
Second: Have you assigned the class to VCs in StoryBoard? (see picture for reference)

Using PFLogInViewController with Swift

I am getting a "use of undeclared type" error when trying to use PFLogInViewController and PFLogInViewControllerDelegate in the default view controller of my Swift project. The code for my ViewController.swift file is below:
import UIKit
class ViewController: UIViewController, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var logInViewController:PFLogInViewController = PFLogInViewController()
logInController.delegate = self
self.presentViewController(logInController, animated:true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I've already imported Parse in the bridging header and am able to send data to the Parse servers. For some reason the PFLogInViewController won't work though. Since Parse hasn't updated their tutorial for Swift, I was hoping someone could give me some insight into how to fix this error. Thanks!
Download the parse SDK, you will see there are a couple of frameworks present. You need to use the ParseUI.framework. Just drag the framework into your frameworks folder in Xcode, and remember to check the 'copy items if needed' option. Then you should also include the framework in you swift file like so:
import ParseUI
And that's it.
I got the same error. This seems to be an issue with the updated Parse SDK. I removed it from my project, linked an older version of the Parse.framework I had stored and no longer received the errors. Hopefully this is resolved soon.