0

我对 ios 开发相当陌生,按照“开始 ios5 开发”一书第 4 章的教程练习,我的代码遇到了一些编译错误。

这是我的头代码 .h 文件的样子

   #import <UIKit/UIKit.h>

   @interface BIDViewController : UIViewController

   @property (strong, nonatomic) IBOutlet UITextField *namefIELD;

   @property (strong, nonatomic) IBOutlet UITextField *numberField;
   @property (strong, nonatomic) IBOutlet UILabel *sliderLabel;
   @property (strong, nonatomic) IBOutlet UISegmentedControl *leftSwitch;
   @property (strong, nonatomic) IBOutlet UISegmentedControl *rightSwitch;
   @property (strong, nonatomic) IBOutlet UIButton *doSomethingButton;

   -(IBAction)textFieldDoneEditing:(id)sender;
   //to initialize the 'done' button when editing to confirm you have finished editing/

   -(IBAction) backgroundTap:(id)sender;
  - (IBAction)sliderChanged:(id)sender;
  - (IBAction)switchChanged:(id)sender;
  - (IBAction)toggleControls:(id)sender;
  - (IBAction)buttonPressed:(id)sender;
  @end

这是我的.m代码,我面临错误“'UISegmentedControl'没有可见的@interface声明选择器'setOn:animated;'

  @synthesize leftSwitch;
  @synthesize rightSwitch;


 - (IBAction)switchChanged:(id)sender {
 UISwitch *whichSwitch = (UISwitch *)sender;
 BOOL setting = whichSwitch.isOn;
 [leftSwitch setOn: setting animated: YES];  //the error lies here/
 [rightSwitch setO: setting animated: YES];  //the error lies here/
 }

 - (IBAction)toggleControls:(id)sender {
 }

 - (IBAction)buttonPressed:(id)sender {
 }
 @end

错误语句是“'UISegmentedControl' 没有可见的@interface 声明选择器'setOn:animated;'

请帮助,将不胜感激并投票赞成:)

@PhilipMills ...这就是我要说的,只要我单击分段控制对象的左侧或右侧,就会在此处的委托标头代码上自动创建一个断点

 #import <UIKit/UIKit.h>

 #import "BIDAppDelegate.h"

 int main(int argc, char *argv[])
 {
       @autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([BIDAppDelegate         class])); //the breakpoint appears here.
       }
 }
4

1 回答 1

1

AUISwitchsetOn:animated:方法,但 aUISegmentedControl没有。我猜你分配的对象leftSwitch不是rightSwitch你想要的(或教程想要的)。

于 2012-09-26T11:51:38.757 回答