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.
Related
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.
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.
I have an application using Swift3 and Eureka Forms 2.0.0. I really love Eureka forms, but my app is leaking memory like crazy and I'm trying to pick it apart to see what's wrong. On the most basic level, I have a custom view controller that contains a table view (I have some other elements around the form that I need to control separately) that I want to tie into a Eureka form. However, even with the most basic possible case, I'm still seeing memory leaks. Here's the view controller I'm testing with:
class TestViewController: FormViewController {
#IBOutlet weak var formTableView: UITableView!
#IBOutlet var mainText: UILabel!
var titleString : String?
override func viewDidLoad() {
NSLog("viewDidLoad")
super.tableView = formTableView
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Just loading this and moving back and forth to another view results in the following leak report in Instruments:
Any advice on this would be much appreciated.
Thanks,
Alex
I am making an app and one of the features is that you take a quiz with some options that ping a web API and show these results. The results pop up on a table view and i have the self.tableview.reload() under the viewdidload() but I still have to navigate back to the previous view controller and hit the results button again to get the proper results to show. How do i make it so the tableview refreshes when it gets called? My second error is the exc_bad_acces (code 1, address: 0x0) and i cannot seem to get it to go away. It happens when the you click on a result in the table view and it takes you to a view controller where a summary of the car is presented. Here is the code used in the file. http://i.imgur.com/FER1VMN.png and http://i.imgur.com/jj2xAvR.png. I can provide more if needed, i hope someone can help!
#adrianB does this help?
the console output says this
class DetailViewController: UIViewController {
var trim : Trims?
#IBOutlet weak var summaryLabel: UILabel!
#IBAction func showSummary(sender: AnyObject) {
summaryLabel.text = trim?.summary (Thread 1: EXC_BAD_ACCESS (code =1, address = 0x0)
}
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.
}`
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: