ios - 基本分段控制不起作用

标签 ios swift segmentedcontrol

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

//
//  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

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

关于ios - 基本分段控制不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45257746/

相关文章:

ios - 更改 UICollectionViewCell subview 框架

ios - 两个不同的 UINavigationController 是否可以连接到同一个 UIViewController,而不会让两个 NavigationBar 出现在屏幕上?

iphone - 弹出UIPickerView不显示

swift - 明暗不切换,分段控制(Swift)

ios - 根据当前显示的 UICollectionViewCell 更改 UISegmentedControl.selectedIndex 值

iOS:使用 OpenGL ES 渲染纯粹基于像素的分形效果?

ios - 从 objective c 转到 swift

ios - 将 Objective-C 库添加到 Swift 项目会增加应用程序的大小吗?

swift - 我什么时候应该使用 deinit?

swift - MXSegmentedPager初始页面