单击模拟器中的段控制器时出现问题。 这是我的代码
#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
这是我得到的错误:
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'
答案 0 :(得分:1)
它正在寻找方法 segmentController ,但是你的类没有。右键单击IB中的Segment Controller,然后删除并重新添加连接。您可能连接了多个操作。单击小X将其删除。
- (IBAction)updateButton:(id)sender