Build succeeds but content doesn't appear when running - ios

When I am running Xcode with below codes it says "build succeeded" but on the simulator nothing is being appeared and I don't know why. Please kindly advise what to fix.
import UIKit
class ViewController: UIViewController {
let numberOfPlanets = 8
let diameterOfEarth = 24859.92 // in miles, where pole to pol
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
print("Welcome to solar system!")
print("There are \(numberOfPlanets) to explore")
print("You are currenly on the Earth, which has a circumstance of \(diameterOfEarth) miles")
firstTextView.text = "Welcome to solar system!"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBOutlet weak var firstTextView: UITextView!
}
added.
thank you Shades enter image description herefor your advice. I checked all you advised but the console is not still printing. I changed the name of "ViewController.swift" to "main.swift" to remove an error saying "expressions are not at the top level". probably it is the reason? I added the screenshot of mine for better understanding. please help.

Related

when i start the app i see a white screen and tells me this error, how can i fix it?

when i start the app i see a white screen and tells me this error, how can i fix it? the error appears in this line:
![myLabel.alpha = 0]
the error is Thread 1: EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode0x0)
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
myLabel.alpha = 0
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
Your #IBOutlet must has become invalid. Maybe you rename it after connecting it or other reason. You should remove the existing one and recreate again. Please check my answer in other thread on how to do this.

iOS 9/Swift 2 input from numpad can't find keyplane

I have some very basic code which reads the text from a textfield when the user presses a button, and updates the text on a label. I have the type of the input field set to number pad.
import UIKit
class ViewController: UIViewController {
#IBOutlet var userGuessTextField: UITextField!
#IBOutlet var resultLabel: UILabel!
#IBAction func guess(sender: AnyObject) {
let randomNumber = String(arc4random_uniform(11))
if randomNumber == userGuessTextField.text {
resultLabel.text = "You're right"
} else {
resultLabel.text = "Wrong! It was a \(randomNumber)"
}
}
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.
}
}
When I trigger my action, xCode throws this error:
Can't find keyplane that supports type 4 for keyboard
iPhone-PortraitTruffle-NumberPad; using
675849259_PortraitTruffle_iPhone-Simple-Pad_Default
EDIT:
Turns out this is not an error at all, but a simple logging statement. I must have accidentally set a breakpoint in my action, giving it the look and feel of a crash. Thank you, first responder.
Laugh uncontrollably and just keep going. It's not an error. It's just a bit of fluff dropped into the console. Ignore it.
It can happened sometime when you update xocode testing on Simulator you can try this fix:
iOS Simulator -> Hardware -> Keyboard -> Connect Hardware Keyboard
This is not an error. It just says cannot find keyplane..
You can switch to simulator keyboard from Hardware -> Keyboard -> Toggle Software Keyboard or simply press cmd + shift + k
You can even ignore this ;-)

Want to make Label Open Website, but iOS Simulator Stuck at Start Screen

I'm making an iPhone app that opens a website when a label is clicked. However, when I run my app, the iOS simulator just stays at the title screen, and doesn't move from there. When I exit the simulator, a dialog box pops up that says, "Exception encountered connecting to CoreSimulatorBridge: connection wen invalid while waiting for a reply". Any help would be greatly appreciated! Thanks.
Here is my code:
import UIKit
class ViewController: UIViewController {
#IBAction func myButton(sender: AnyObject) {
UIApplication.sharedApplication().openURL(NSURL(string: "http://www.mcmastermhs.com")!)
}
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.
}
}
Try this:
Quit Xcode and Simulator.
In Terminal, run killall -9 com.apple.CoreSimulator.CoreSimulatorService.
Restart Xcode.
If that doesn't resolve it, restart your computer.

UITextView does not update its height after trying to change its height programmatically

I just want to modify the height of a UITextView.
The log resulting from the code below, says that in fact, the
height changed from 30 to 400:
println(txtresponses.frame.height) // returns 30
var newFrame:CGRect=txtresponses.frame
newFrame.size.height=400
txtresponses.frame=newFrame
println(txtresponses.frame.height) // returns 400
However, visually, the UITextView "txtresponses" remains with the same size.
I am new to Swift and Xcode, so all my tricks are already exhausted here, and I dont know if it is an iOS version issue, or some typical Xcode whim.
What is the correct way to modify a UITextView ´s height?
Make sure to call txtresponses.frame=newFrame in the main thread.
dispatch_async(dispatch_get_main_queue()) {
txtresponses.frame=newFrame
}
All UI updates must be done from the main thread.
Its not work because I think you are using Autolayout with constraint. Please check below url which may help you - Change height constraint programmatically
Might be issue Autolayout. u just remove the autolayout and check it will work. Check below code i hope it will help you.
Example :
import UIKit
class ViewController: UIViewController {
#IBOutlet var textView: UITextView!
#IBOutlet var butt: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
textView.backgroundColor = UIColor.lightGrayColor()
// 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 buttonAction(sender: UIButton) {
var newFrame:CGRect=textView.frame
newFrame.size.height=400
textView.frame=newFrame
}
}
Screen 1:
Screen 2:

UIScrollView and UITextView

I'm new to Swift (and programming in general). I'm having some issues getting a Text View to scroll.
I've created outlets for the scroll view and the text view already.
I've found a boat load of people asking the same question on Stack Overflow/Reddit but I am still unable to fix the issue due to just not really knowing what I'm doing.
Here is a screenshot of my view controller so you can see the text I am referring to:
And here is the code I have in my viewcontroller.swift file:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var scrollView: UIScrollView!
#IBOutlet weak var descriptionTextView: UITextView!
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.scrollView.layoutIfNeeded()
self.scrollView.contentSize = self.descriptionTextView.bounds.size
}
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.
}
}
I'm getting the following green error message when I build:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
I would love some help from anyone if you are feeling kind or have the time to chime in.
Call me crazy, but would it be silly to believe that it is just overwhelmingly difficult to achieve such a simple thing as scrollable text? I feel like I'm missing something.
Thanks to anyone who may be able to lend a hand.

Resources