I'm trying to build a very simple app just to see how the UISlider works. I've seen several tutorials and followed them to the letter but nothing seems to work.
I keep getting this error exactly when I try to move the Slider in the simulator, after I've successfully built
This is my whole code. It's really simple but I can't understand why the Slider won't work.
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var noteBottomLabel: UILabel!
#IBOutlet weak var sliderNoteBottom: UISlider!
#IBAction func changedSliderNoteBottom(sender: AnyObject) {
var noteBottomValue = Int(sliderNoteBottom.value)
noteBottomLabel.text = "\(noteBottomValue)"
}
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.
}
Can you see any problems with this? I'm probably noobing out, but I've looked everywhere and can't find an explanation
import UIKit
import CoreFoundation
class ViewController2 : UIViewController {
override func viewDidLoad() {
super.viewDidLoad();
}
#IBOutlet weak var slider: UISlider!
#IBAction func slidervaluechanged(sender: UISlider) {
print(Int(slider.value))
}
}
I have tried your code just made the print of slider.value rather than putting it on label .
But I have used Xcode 7.3 , I don't think this should be problem with Xcode .Use the sender as UISlider when making an #IBAction that looks better . Brings up the value of 0 at bottom and 1 at top.
Related
When I go to run my first program in Swift (I have only been studying the language for about a month - my first programming language), I receive the error: "error: attach by pid '2423' failed -- unable to attach". Here is my code if anyone can point out the problem for me. This is also my first question in Stackoverflow, so please let me know if this is an appropriate question. Thanks!
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var nameText: UITextField!
#IBOutlet weak var nameDisplayed: UILabel!
#IBAction func submitButton(_ sender: AnyObject) {
nameText.text = nameDisplayed.text
}
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 am new to Swift and am trying to make a basic application that displays a string based on entered text.
I understand that with iOS 9 and Swift 2.0, there are several new changes. I am watching a tutorial from iOS 8 and Swift 1.2 and noticed that the code I am trying to run is not compiling, stating that I need an "!" to unwrap a variable. What is the best way to learn about unwrapping and when it is necessary? A tutorial or video would be extremely helpful:
import UIKit
class ViewController: UIViewController {
#IBOutlet var resultLabel: UILabel!
#IBOutlet var age: UITextField!
#IBOutlet var convertedAge: UILabel!
#IBAction func checkAge(sender: AnyObject) {
var enteredAge = Int(age.text)
//exclamation mark "unwraps" a variable
//a way for the programmer to ensure that a value will be an int
var catYears = enteredAge! * 7
resultLabel.text = "Your cat is \(catYears)"
print(age.text)
}
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.
}
}
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/OptionalChaining.html
I am suggesting apple's own source for this purpose. If you can pay for the course, also Lynda.com has a nice Swift essentials course
I am trying to call the entire menu with Month title from Mozharovsky/CVCalendar but I'm not sure what function will call this out?
This is the current code I am using:
import UIKit
import CVCalendar
class ViewController: UIViewController, CVCalendarViewDelegate, CVCalendarMenuViewDelegate {
#IBOutlet weak var calendarView: CVCalendarView!
#IBOutlet weak var menuView: CVCalendarMenuView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.navigationController?.navigationBar
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
calendarView.commitCalendarViewUpdate()
menuView.commitMenuViewUpdate()
}
func presentationMode() -> CalendarMode {
return CalendarMode.MonthView
}
func firstWeekday() -> Weekday {
return Weekday.Sunday
}
}
This is the what is rendered when compiled:
If you want to see the month title also you need to create a UIlabel and UIlabel outlet as such:
#IBOutlet weak var monthLabel: UILabel!
I got this answer by copying the code from Mozharovsky/CVCalendar Demo ViewController.swift file
This is driving me crazy. I am trying to un-hide a hidden UIView on button click but its not working. Here is the code
import UIKit
class DownloadViewController: UIViewController {
#IBOutlet var activityView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.activityView.hidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func downloadAction(sender: AnyObject) {
self.activityView.hidden = false
}
}
Please help me. This is driving me nuts, that its not doing such a simple thing.
Make sure that your outlet is connected to the correct button in Interface Builder, try connecting it again by ctrl-dragging from the button in IB to the #IBOutlet code.
This code works, are you getting an error or does the button not do anything?
Swift 3
import UIKit
class DownloadViewController: UIViewController {
#IBOutlet var activityView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.activityView.isHidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func downloadAction(sender: AnyObject) {
self.activityView.isHidden = false
}
}
My first question here. I'm making the jump from Delphi and Pascal to Xcode and Swift and feeling totally overwhelmed by the change.
I'm simply attempting to change the text of a label when a button is clicked. Here is my code from ViewController.swift
import Cocoa
class ViewController: NSViewController {
#IBOutlet weak var Label1: NSTextField!
#IBOutlet weak var ChangeText: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
#IBAction func ButtonPressed(sender: AnyObject) {
Label1.stringValue = "Hello World"
}
override var representedObject: AnyObject? {
didSet {
// Update the view, if already loaded.
}
}
When I run the application as soon as I click the button the application hangs.
I've also tried exchanging stringValue with text but NSTextField does not use this. I can't seem to make the label show up as UITextField.
What am I doing wrong?