2016-07-30 78 views
0

我點擊模擬器中的段控制器時出現問題。 這裏是我的代碼Xcode段控制器錯誤

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

回答

1

它尋找方法segmentController,但你的類沒有一個。右鍵單擊IB中的段控制器,然後刪除並重新添加連接。您可能連接了多個操作。點擊小X將其刪除。

- (IBAction)updateButton:(id)sender