0
구현 파일에서 오류 ("switchChanged"선언되지 않음)가 발생하지만 문제를 찾을 수 없습니다. 너 나 좀 도와 줄 수있어?디버깅 도움이 필요합니다 switchChanged 메서드
TIA
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
콜론은 오류 메시지에서 제외되었습니다. 그건 내 실수가 아니야. 그것은 Xcode가 나에게 돌려 준 것입니다. 내가 말할 수있는 한, 모든 콜론을 switchChanged : 메소드에 포함 시켰고, 헤더에도이 콜론을 포함 시켰기 때문에 오류가 어디에 있는지 알 수 없습니다. – pdenlinger
이것은 컴파일 타임 오류입니다. 맞습니까? 런타임에 문제가 발생했다면 인식 할 수없는 선택기에 대한 오류가 발생합니다. 그렇다면 컴파일러가 문제가 발생한 행을 표시하지 않습니까? – Caleb
문제점을 발견했습니다. 위의 메서드 (toggleControls)에 닫는 대괄호가 없어서 문제가 발생했습니다. 일단 그것이 고쳐지면 모든 것이 OK가되었습니다. – pdenlinger