简体   繁体   English

Xcode段控制器错误

[英]Xcode segment controller error

I have an issue when I click on the segment controller in the simulator. 单击模拟器中的段控制器时出现问题。 Here's my code 这是我的代码

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UITextField *inputField;

@property (weak, nonatomic) IBOutlet UILabel *outputField;

@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentController;
@end

@implementation ViewController

- (IBAction)updateButton:(id)sender {
    NSMutableString *buf = [NSMutableString new];
    switch (self.segmentController.selectedSegmentIndex) {
        case 0:
            [buf appendString: @"unit two"];
            break;
        case 1:
            [buf appendString: @"unit three"];
            break;
        default:
            [buf appendString: @"unit four"];
            break;
    }
    self.outputField.text = buf;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

Here's the error I get: 这是我得到的错误:

2016-07-29 17:40:45.506 UnitConverter[3213:534645] -[ViewController segmentController:]: unrecognized selector sent to instance 0x7fae71dbd040 2016-07-29 17:40:45.509 UnitConverter[3213:534645] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController segmentController:]: unrecognized selector sent to instance 0x7fae71dbd040'

It's looking for the method segmentController , but your class doesn't have one. 它正在寻找方法segmentController ,但是您的类没有一个。 Right click on the Segment Controller in IB and remove and re-add the connection to. 右键单击IB中的网段控制器,然后删除并重新添加连接。 You may have more than one Action connected. 您可能连接了多个动作。 Click the little X to remove them. 单击小X删除它们。

 - (IBAction)updateButton:(id)sender 

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

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