我只是Swift编码的初学者.我的想法很简单,这是一个带有两个按钮的应用程序.单击时,文本字段将更改其文本.在Main.StoryBoard中,我添加了一个文本字段和两个按钮.在ViewController.swift文件中.我这样写:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textfield: UITextField!
@IBOutlet weak var button: UIButton!
@IBOutlet weak var button2: UIButton!
@IBAction func action1(_ sender: UIButton) {
textfield.text="you just clicked on button1"
}
@IBAction func action2(_ sender: UIButton) {
textfield.text="you just clicked on button2"
}
}
Run Code Online (Sandbox Code Playgroud)
它应该是好的.但是,出现错误,显示:
thread1:信号SIGABRT
在文件AppDelegate.swift行:
class AppDelegate: UIResponder, UIApplicationDelegate
Run Code Online (Sandbox Code Playgroud)
我的代码出了什么问题?
背景:
\n\n我试图从数组类型中提取所有原型函数。
\n\nconst arrayProto = Array.prototype \nconst arrayMethods = Object.create(arrayProto) \nRun Code Online (Sandbox Code Playgroud)\n\narrayMethods回报Array\xc2\xa0{}
我发现所有方法都是原始(浅紫色),但没有一个被计算在内。如果我更改arrayProto为像 [1,2,3] 这样的普通数组,我可以通过 arrayMethods[i] 获取数字,因为所有数字都列出在\ n我的第一个想法是浅紫色的被忽略或不知何故不属于 arrayMethods. 但是我找不到有关控制台这部分的任何文档。\n为什么以及如何解决它?
我想将按钮调整为正方形,这是我的代码:
let button = UIButton()
button.backgroundColor = UIColor.red
button.translatesAutoresizingMaskIntoConstraints = false
//method one
//button.widthAnchor.constraint(equalToConstant:44.0).isActive = true
//button.heightAnchor.constraint(equalToConstant: 44.0).isActive = true
//method two
button.frame.size = CGSize(width: 20.0, height: 20.0)
button.addTarget(self, action: #selector(ratingButtonTapped(button: )), for: .touchUpInside)
addArrangedSubview(button)
Run Code Online (Sandbox Code Playgroud)
我已经尝试了这两种方法,但是它们似乎都没有解决,错误显示方法一中出现了一些错误,方法二中没有显示任何错误.当我运行代码时,按钮在容器中完成.这有什么不对?