ios - Xcode 段 Controller 错误

标签 ios objective-c xcode

我在模拟器中点击段 Controller 时遇到问题。 这是我的代码

#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'

最佳答案

它正在寻找方法segmentController,但您的类没有。右键单击 IB 中的段 Controller 并删除并重新添加连接。您可能连接了多个 Action。单击小 X 将其删除。

 - (IBAction)updateButton:(id)sender 

关于ios - Xcode 段 Controller 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38669303/

相关文章:

iphone - 线程1:信号SIGABRT xcode 4.4 ios 5.1 Objective-c帮助>。<

ios - 如何快速缩放多个页面中的图像

ios - RestKit 和 CocoaPods 的 Xcode 7 链接器错误

iphone - iCloud:KeyValue 存储还是文档存储?

xcode - 无法在macOS 10.14 Mojave下加载Info.plist错误Xcode 10

objective-c - 从另一个类访问 ccsprite

iphone - 如何修复我的 [UIScreen mainscreen] 将 iPhone 5 识别为 iPhone 4

ios - UIButton 标题对齐不会更改为 RTL 中的正确方向

ios - 搜索属性列表时如何检测错误?

ios - UIViewController 的 subview 最初在什么时候明确布局?