我的" AppDelegate.swift"文件将无法连接到我的IBAction功能! 请帮忙!!!!
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { return true }
func applicationWillResignActive(application: UIApplication) { }
func applicationDidEnterBackground(application: UIApplication) { }
func applicationWillEnterForeground(application: UIApplication) { }
func applicationDidBecomeActive(application: UIApplication) { }
func applicationWillTerminate(application: UIApplication) { }
}
//在这一行的下方,我包含了" ViewController.swift"档案:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var Question: UILabel!
@IBOutlet weak var Answer1: UIButton!
@IBOutlet weak var Answer2: UIButton!
var CorrectAnswer = String()
override func viewDidLoad() {
super.viewDidLoad()
RandomQuestions() }
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning() }
func RandomQuestions() {
var RandomNumber = arc4random() % 2
RandomNumber += 1
switch(RandomNumber) {
case 1 :
Question.text = "What are two languages used to develop Mac iOS apps?"
Answer1.setTitle("HTML & JavaScript", forState: UIControlState.Normal)
Answer2.setTitle("Objective-C & Swift", forState: UIControlState.Normal)
CorrectAnswer = "2"
break
case 2 :
Question.text = "Which Mac iOS language does not need semicolons?"
Answer1.setTitle("Swift", forState: UIControlState.Normal)
Answer2.setTitle("Objective-C", forState: UIControlState.Normal)
CorrectAnswer = "1"
break
default :
break } }
@IBAction func Answer1(sender: AnyObject) {
if (CorrectAnswer == "1") { Question.text = "You are Right!" }
else if (CorrectAnswer == "2") { Question.text = "You are Right!" }
}
@IBAction func Answer2(sender: AnyObject) {
if (CorrectAnswer == "1") { Question.text = "You are Right!" }
else if (CorrectAnswer == "2") { Question.text = "You are Right!" }
}
}