简体   繁体   English

Swift 3中的背景颜色更改

[英]Background color change in Swift 3

import UIKit

class ViewController: UIViewController {

    @IBAction func CyanBackground(sender: AnyObject) {
        view.backgroundColor = UIColor.cyan
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a      
    }
}

I am simply trying to change the background color in Swift, but when I try to click the button I made, Xcode goes to a different page and highlights this line: 我只是试图在Swift中更改背景颜色,但是当我尝试单击我创建的按钮时,Xcode转到另一个页面并突出显示此行:

class AppDelegate: UIResponder, UIApplicationDelegate {

This shows up in the console: 这将显示在控制台中:

( 0 CoreFoundation 0x000000010915a34b exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010660121e objc_exception_throw + 48 2 CoreFoundation 0x00000001091c9f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x00000001090dfc15 __forwarding + 1013 4 CoreFoundation 0x00000001090df798 _CF_forwarding_prep_0 + 120 5 UIKit 0x0000000106ad26c8 -[UIApplication sendAction:to:from:forEvent:] + 83 6 (0 CoreFoundation 0x000000010915a34b exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010660121e objc_exception_throw + 48 2 CoreFoundation 0x00000001091c9f34-[NSObject(NSObject)doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x00000001090_d000000_0000000_00000000_Precision_0000000_00000000_Cedward 0x00000000_90000000_Cedward 0x0000000090dFc13for 0C0000000Kit_for 00000000000000090dFc13 0For 00000000000000090dFc13 0 :to:from:forEvent:] + 83 6

Any experienced Swift developers who can help me out? 有经验的Swift开发人员可以帮助我吗?

Thanks, Fareed 谢谢,车费

The problem is with an outlet. 问题出在插座上。 Maybe you deleted the line of code and/or replaced it, but the link still exists. 也许您删除了代码行和/或替换了代码行,但是链接仍然存在。

In your main.storyboard check all the outlets, control+(click on outlet) and check if it is linked to something. 在您的main.storyboard中,检查所有插座,然后按Control +(单击插座)并检查它是否链接到某物。 Once you correct that it should run with no problems. 一旦纠正,它应该可以正常运行。

Try this...you have problem with your IBOutlet... 试试这个...您的IBOutlet有问题...

   @IBAction func Background Cyan(sender: UIButton) {
   view.backgroundColor = UIColor.cyan  
   }

Paste this code into yourstoryboard and reconnect the outlet. 将此代码粘贴到您的故事板上,然后重新连接插座。 This will do the job... 这样就可以了...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM