Xcode 需要帮助调试已更改的方法吗

Xcode 需要帮助调试已更改的方法吗,xcode,ios4,Xcode,Ios4,我在实现文件中遇到错误(“switchChanged”未声明),但找不到问题。你能帮我吗 短暂性脑缺血发作 ViewController.m #import "Control_FunViewController.h" @implementation Control_FunViewController @synthesize nameField; @synthesize numberField; @synthesize sliderLabel; @synthesize leftSwitch

我在实现文件中遇到错误(“switchChanged”未声明),但找不到问题。你能帮我吗

短暂性脑缺血发作

ViewController.m

#import "Control_FunViewController.h"



@implementation Control_FunViewController

@synthesize nameField;
@synthesize numberField;
@synthesize sliderLabel;
@synthesize leftSwitch;
@synthesize rightSwitch;
@synthesize doSomethingButton;

-(IBAction)sliderChanged:(id)sender
{
    UISlider *slider = (UISlider *)sender;
    int progressAsInt = (int)(slider.value + 0.5f);
    NSString *newText = [[NSString alloc] initWithFormat:@"%d",progressAsInt];
    sliderLabel.text = newText;
    [newText release];
}

-(IBAction)textFieldDoneEditing:(id)sender
{
    [sender resignFirstResponder];
}

-(IBAction)backgroundTap:(id)sender
{
    [nameField resignFirstResponder];
    [numberField resignFirstResponder];
}

-(IBAction)toggleControls:(id)sender
{
    if ([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
    {
        leftSwitch.hidden = NO;
        rightSwitch.hidden = NO;
        doSomethingButton.hidden = YES;
    }
    else {
        leftSwitch.hidden =YES;
        rightSwitch.hidden =YES;
        doSomethingButton.hidden = NO;
    }
-(IBAction)switchChanged:(id)sender
    {
        UISwitch *whichSwitch = (UISwitch *)sender;
        BOOL setting = whichSwitch.isOn;
        [leftSwitch setOn:setting animated:YES];
        [rightSwitch setOn:setting animated:YES];
    }
-(IBAction)buttonPressed
    {
        //TODO: Implement Action Sheet and Alert
    }
}





/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


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


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [nameField release];
    [numberField release];
    [sliderLabel release];
    [leftSwitch release];
    [rightSwitch release];
    [doSomethingButton release];
     [super dealloc];
}

@end
ViewController.h

#import <UIKit/UIKit.h>

#define kSwitchesSegmentIndex   0

@interface Control_FunViewController : UIViewController {
    UITextField *nameField;
    UITextField *numberField;
    UILabel *sliderLabel;
    UISwitch *leftSwitch;
    UISwitch *rightSwitch;
    UIButton *doSomethingButton;
}

@property(nonatomic,retain)IBOutlet UITextField *nameField;
@property(nonatomic,retain)IBOutlet UITextField *numberField;
@property(nonatomic,retain)IBOutlet UILabel *sliderLabel;
@property(nonatomic,retain)IBOutlet UISwitch *leftSwitch;
@property(nonatomic,retain)IBOutlet UISwitch *rightSwitch;
@property(nonatomic,retain)IBOutlet UIButton *doSomethingButton;

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


@end
#导入
#定义kSwitchesSegmentIndex 0
@接口控制\u FunViewController:UIViewController{
UITextField*nameField;
UITextField*数字字段;
UILabel*滑动标签;
UISwitch*左开关;
UISwitch*右开关;
UIButton*doSomethingButton;
}
@属性(非原子,保留)IBOutlet UITextField*nameField;
@属性(非原子,保留)IBOutlet UITextField*numberField;
@属性(非原子,保留)IBUILabel*滑块标签;
@属性(非原子,保留)IBUISwitch*leftSwitch;
@属性(非原子,保留)IBUISwitch*rightSwitch;
@属性(非原子,保留)IBUIButton*doSomethingButton;
-(iAction)textFieldDoneEditing:(id)发送方;
-(iAction)背景点击:(id)发送者;
-(iAction)滑块已更改:(id)发送方;
-(iAction)切换控件:(id)发送方;
-(iAction)开关已更改:(id)发送方;
-(IBAction)按钮按下;
@结束

冒号(:)是方法名称的一部分,但您尚未将其包含在错误消息中。可能是您刚刚忘记了,但是如果您从某处调用-switchChanged(无冒号),或者如果您使用action-switchChanged(无冒号)连接了一个控件,这就是问题所在。可能您后来添加了冒号和发件人参数?

错误消息中没有冒号;那不是我的错,把它漏掉了。这就是Xcode返回给我的东西。据我所知,我已经在switchChanged:方法中包含了所有冒号,并且我还将其包含在标题中,因此我无法确定错误在哪里。这是一个编译时错误,对吗?如果它发生在运行时,您将得到一个关于无法识别的选择器的错误。如果是这样的话,编译器没有指出问题发生的那一行吗?找到了问题。上述方法(toggleControls)缺少闭合括号,这导致了问题。一旦修复了,一切都正常了。