I thought to design the program like this.
The user type the data in each text fields; Name, Passwords and Comments.
By press the button, store the input data into the Firebase storage.
However, the error occurred.
I wonder which parts need to fix or add.
Code
Error
private let database = Database.database().reference()
#IBOutlet weak var NameInput: UITextField!
#IBOutlet weak var Passwords: UITextField!
#IBOutlet weak var Rate: UISegmentedControl!
#IBOutlet weak var Comment: UITextField!
#IBOutlet weak var UploadButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
#IBAction func UbuttonPressed(_ sender: Any) {
let review_data: [String: Any?] = [
"Name": NameInput.text,
"Passwords": Passwords.text,
// "Rate": Rate.text,
"Comment": Comment.text
]
database.child("Review_\(Int.random(in: 0..<1000))").setValue(review_data)
}
You probably have a storyboard reference to one of the #IBOutlets which you renamed/deleted in your source code, but haven't removed/changed it in the storyboard. See this article for more info.
Related
I want to declare a global array of NSTextFields, but "Class ViewController has no initializers." Yes, global, but static.
class ViewController: NSViewController {
#IBOutlet weak var TextField01: NSTextField!
#IBOutlet weak var TextField02: NSTextField!
#IBOutlet weak var TextField03: NSTextField!
var fieldArray: [NSTextField]
override func viewDidLoad() {
super.viewDidLoad()
fieldArray = [TextField01, TextField02, TextField03]
}
I thought that the problem was the compiler not knowing about the main storyboard; that's why I didn't assign values to my fieldArray. It would appear that I need to declare (initialize?) fieldArray in some other way.
When the picture description is long, my picture disappears, I can't see it. How can I show full size of text and full size of images?
How can I scroll the text up and down?
FavoriteDetailViewController
import UIKit
import ProgressHUD
class FavoriteDetailViewController: UIViewController {
#IBOutlet weak var shortdescriptionLabel: UILabel!
#IBOutlet weak var favoriteImageView: UIImageView!
#IBOutlet weak var favoriteTitleLabel: UILabel!
#IBOutlet weak var descriptionLabel: UILabel!
#IBOutlet weak var nameField: UITextField!
var breed: Breed!
override func viewDidLoad() {
super.viewDidLoad()
populateView()
}
private func populateView() {
favoriteImageView.kf.setImage(with: breed.image?.asUrl)
favoriteTitleLabel.text = breed.name
descriptionLabel.text = breed.description
shortdescriptionLabel.text = breed.shortDescription
}
#IBAction func favoriteButton(_ sender: UIButton) {
guard let name = nameField.text?.trimmingCharacters(in: .whitespaces),
!name.isEmpty else {
ProgressHUD.showError("Please enter your name")
return
}
print("Hello \(name)")
}
}
I made the text smaller but it's very illegible
I dropped the spacing, it looks bad too
I want to make the whole text look nice and not spoil the picture. What is the solution? Is it possible to move the label up and down?
I'm adding a new TableVIewto the project and I'm also creating a custom class fro the cell. I'm doing as usual : New file/ Cocoa Touch Class / UITableViewCell / name. As soon as I start adding properties I get the error dough properties are declared as!. It doesn't happen on my other custom cell class. Can you see what am I doing wrong with this new class?
No error on this class :
import UIKit
class CalendarTableViewCell: UITableViewCell {
#IBOutlet weak var dayLabel: UILabel!
var cellId: String!
var cellWeekday: Int!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func prepareForReuse() {
super.prepareForReuse()
// Set your default background color, title color etc
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
and the new class that makes xCode complain:
import UIKit
class ProductTableViewCell: UITableViewCell {
#IBOutlet weak var productImageView: UIImageView!
#IBOutlet weak var productIDLabel: UILabel!
#IBOutlet weak var productIDInfoLabel: UILabel!
#IBOutlet weak var categoryLabel: UILabel!
#IBOutlet weak var categoryInfoLabel: UILabel!
#IBOutlet weak var nameLabel: UILabel!
#IBOutlet weak var nameInfoLabel: UILabel!
#IBOutlet weak var priceLabel: UILabel!
#IBOutlet weak var priceInfoLabel: UILabel!
#IBOutlet weak var quantityLabel: UILabel!
#IBOutlet weak var quantityInfoLabel: UILabel!
var productImage: UIImage!
var category: String!
var productId: String!
var name: String!
var price: String
var vendor: String!
var cellId: Int64
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
It's something I overlooked for sure but I can't spot it.
What should I check?
Your var cellId: Int64 is not initialized. In first cell you explicitly specified that you will initialize it before use with exclamation mark, but not in the second cell.
I'm new with Swift, but what I would like to do basically is
now what the user selected for Q1 : Q 4,
if for example the user selected Yes at Q1, no to Q2 then I would like to add a string to the clipboard :
Q1 : Question one is there : Yes
Q2 : Question two is here : No
and last thing from the button "done"
I would like to added to the previous clipboard and copy what ever the text is on the first textfield and put all together into the clipboard
// Case Questions
#IBOutlet weak var qUestionOne: NSPopUpButton!
#IBOutlet weak var qUestionTwo: NSPopUpButton!
#IBOutlet weak var qUestionTree: NSPopUpButton!
#IBOutlet weak var qUestionFor: NSPopUpButton!
// CaseNote
#IBOutlet weak var cAseNoteTextField: NSTextField!
// Draft
#IBOutlet weak var dRaftNote: NSTextField!
// buttons
#IBAction func dOneButton(_ sender: Any) {
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
Ello! I am working on a notes app for mac, using swift as the language. I am currently working on a save and load feature, and have run across an error I am not sure how to fix. Here is the problematic code:
import Cocoa
class NoteViewController: ViewController {
#IBOutlet weak var notefield: NSTextField!
#IBOutlet weak var savenamefield: NSTextField!
#IBOutlet weak var loadnamefield: NSTextField!
#IBAction func save(sender: AnyObject) {
// The line below gets the error: Thread 1: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0
NSUserDefaults.standardUserDefaults().setObject(notefield.stringValue, forKey: savenamefield.stringValue)
}
#IBAction func load(sender: AnyObject) {
var name = loadnamefield.stringValue;
var lnote = NSUserDefaults.standardUserDefaults().objectForKey(name)
notefield.stringValue = lnote as! String
}
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
}
}
What might I be doing wrong?
I figured it out. With some testing, I discovered that everything worked until I added notefield.stringValue into the code.I then realized that I had this is a different window. The code is covering 3 different windows, 2 of which are popups. notefield is the only element I had inside the code from the main window. I moved all of the elements to the same window, and recoded the entire thing. I got it working well using the following code:
import Cocoa
class NoteViewController: ViewController {
#IBOutlet weak var notefield: NSTextField!
#IBOutlet weak var savenamefield: NSTextField!
#IBOutlet weak var loadnamefield: NSTextField!
#IBAction func save(sender: AnyObject) {
NSUserDefaults.standardUserDefaults().setObject(notefield.stringValue, forKey: savenamefield.stringValue)
}
#IBAction func load(sender: AnyObject) {
notefield.stringValue = NSUserDefaults.standardUserDefaults().objectForKey((loadnamefield?.stringValue)!) as! String
}
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
}
}
Please note that I am supplying this code as a guideline only. Thanks for the help that was given.