UIButton disappears after succesfull build - swift

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.

Related

An error is popping up when I try to run my Xcode project called "Thread 1: Signal SIGABRT"

I am trying to run a simple button that you click. But when I run the simulator, the app launches, and then the simulator stops and an error pops up saying "Thread 1: Signal SIGABRT". I am completely new to Xcode. Could someone please help me?
I tried the linking and I did some research but nothing worked.
import UIKit
import SpriteKit
import GameplayKit
class GameViewController: UIViewController {
#IBAction func Button(_ sender: UIButton) {
print("Hello World!"
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
I want it to print "Hello World", but that isn't happening.
It looks like the outlets you created are not connected to your Storyboard subviews anymore. You can just check it out doing right-click on you button and seeing if your #IBAction is still there.
You can try out few of these points:
First check your #IBAction i.e your button action is connected to your view controller in main.storyboard
Then put a breakpoint in the action function and check if it is executing or not
Look at the connection by right click on outlets connection and see if its showing a warning yellow sign if showing and put a right connection.
- For more information about : USE OF BREAKPOINTS
Regarding Breakpoints see these screenshots

IBOutlet button not working - Swift

I have searched for a similar question to this but cannot find it because mine is very obscure.
I am currently developing a social network app. All my code seems to be correct. However, there is the share button that is not working. I will attach the code here:
#IBOutlet weak var shareBtn: UIButton!
which is in one of my files to connect it up and:
#objc func toCreatePost (_ sender: AnyObject) {
performSegue(withIdentifier: "toCreatePost", sender: nil)
}
Before you ask, all of my segues are connected, the buttons are connected to the code and the identifier is correct.
I don't know if it could be an error in Xcode itself or my code, but the button clicks when it is run however it does not do anything. Help would be appreciated.
The error is that when the button is clicked it does not do anything and will not go to the next ViewController even though the code seems to be correct.
#IBAction func toCreatePost (_ sender: AnyObject) {
performSegue(withIdentifier: "toCreatePost", sender: nil)
}
Above is the code with an IBaction which I edited which now gives me a crash. The crash is a Thread 1: signal SIGABRT
Here is my main.storyboard
See this for view-based issues click here
It seems you have not added navigation controller before the view controller from where you have to perform segua action.
if your problem still not resolved try to push manualy without segua

How to keep LaunchScreen storyboard screen longer till WebUI loads

I am new to IOS app development. My requirement is to develop an app which shows an application on user login.
when users opens an app, Storyboard launch screen is displayed immediately and then a blank white screen is displayed after that login page is displayed for user login. I think WEbUI is taking time to load.
The problem here is the blank white screen which is getting displayed after launch screen. In order to avoid that I am trying to wait till web loads by having splash screen, But adding those functions are not working.Please let me know the solution with code.
Here is my code-- ViewController.swift
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var backgroundImageView: UIImageView!
#IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = URL (string: "https://www.google.com");
let requestObj = URLRequest(url: url!);
webView.loadRequest(requestObj);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Please let me know if there any other solution..
Make one extra controller that looks like your launch screen present it after launch screen but without animation so user can not see that you change screen white webview to load on this screen then present viewcontroller with webview
I make test project for you
You can download from: http://www.filedropper.com/testproject

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)

SwiftSpinner not working on UIViewController.

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.