基本分段控制不起作用

Basic segmented control not working

我正在尝试将分段控件实现到视图控制器中,但每次我尝试在模拟器上点击控制器时,应用程序都会崩溃。但我真的不知道我的代码来自哪里。对于添加的上下文:尝试更改具有四个段的四个标签。

//
//  AboutViewController.swift
//  Yiives
//
//  Created by Patrick van der Nat on 7/22/17.
//  Copyright © 2017 Origen. All rights reserved.
//

import UIKit

class AboutViewController: UIViewController {
    @IBOutlet weak var segmentedControl: UISegmentedControl!
    @IBOutlet weak var textLabel: UILabel!

    @IBAction func indexChanged(_ sender: Any) {
        switch segmentedControl.selectedSegmentIndex
        {
        case 0:
            textLabel.text = "First Segment Selected";
        case 1:
            textLabel.text = "Second Segment Selected";
        case 2:
            textLabel.text = "Third Segment Selected";
        case 3:
            textLabel.text = "Fourth Segment Selected";
        default:
            break
        }
    }
}

这是给出的错误:

2017-07-22 20:02:31.059244+0200 Yiives[369:50130] -[Yiives.AboutViewController segmentControl:]: unrecognized selector sent to instance 0x100b37b40
2017-07-22 20:02:31.060083+0200 Yiives[369:50130] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Yiives.AboutViewController segmentControl:]: unrecognized selector sent to instance 0x100b37b40'
*** First throw call stack:
(0x183a1afe0 0x18247c538 0x183a21ef4 0x183a1ef54 0x18391ad4c 0x189b81010 0x189b80f90 0x189b6b504 0x189c9a764 0x189d522e0 0x189b80390 0x189b7b728 0x189b4c33c 0x18a346014 0x18a340770 0x18a340b9c 0x1839c942c 0x1839c8d9c 0x1839c69a8 0x1838f6da4 0x185360074 0x189bb1058 0x1000a8544 0x18290559c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

您已连接名为 segmentControl: 的操作方法,但在您的代码中该操作方法名为 indexChanged

更新您从分段控制插座到操作方法的连接。