2009-07-12 5 views
1

UIView.h왜 main 파일의 헤더 파일에서 @properties를 인식하지 못합니까?

#import <UIKit/UIKit.h> 
#import <Foundation/Foundation.h> 

@interface UIView : UIResponder { 
    IBOutlet UILabel *endLabel; 
    IBOutlet UIButton *goButton; 
    IBOutlet UITextField *textBox1; 
    IBOutlet UITextField *textBox2; 

    @property(nonatomic, retain) UILabel *endLabel; 
    @property(nonatomic, retain) UIButton *goButton; 
    @property(nonatomic, retain) UITextField *textBox1; 
    @property(nonatomic, retain) UITextField *textBox2; 
} 
- (IBAction)goButtonClicked; 
@end 

UIView.m

#import "UIView.h" 

@implementation UIView 

@synthesize textBox1, goButton; 
@synthesize textBox2, goButton; 
@synthesize textBox1, endLabel; 
@synthesize textBox2, endLabel; 
@synthesize goButton, endLabel; 

- (IBAction)goButtonClicked { 

} 

@end 
+0

내 게시물에 언급 된대로; UIView를 다시 구현하려고합니다. 이 클래스는 이미 분명히 존재하기 때문에 이것은 분명히 좋지 않습니다. 클래스의 이름을 변경하고 UIView의 하위 클래스로 구현해야합니다 (예 : MyView). –

답변

4

우리는의 @synthesize의 미친 약간 간다? 나는 여기서 귀하의 주된 문제는 @property 선언이 이후 인 후 @interface이 될 필요가 있다고 믿습니다.

나는 컴파일러가 그린란드 크기의 붉은 깃발을 던지지 않은 것에 놀랐다. '

또한 사용자 정의 서브 클래스를 UIView으로 만들 예정이었습니다. MyView을 사용하겠습니다.

//MyView.m -- correct synthesize declaration 
@synthesize textBox1, goButton, textBox2, endLabel; 

//MyView.h -- correct interface declaration 
#import <UIKit/UIKit.h> 
#import <Foundation/Foundation.h> 

@interface MyView : UIView { 
    IBOutlet UILabel *endLabel; 
    IBOutlet UITextField *textBox1; 
    IBOutlet UITextField *textBox2; 
    IBOutlet UIButton *goButton; 
} 

@property(nonatomic, retain) UIButton *goButton; 
@property(nonatomic, retain) UILabel *endLabel; 
@property(nonatomic, retain) UITextField *textBox1; 
@property(nonatomic, retain) UITextField *textBox2; 

@end 
+0

실제로 실제로 그 (것)들을 가지고 있었지만 여전히 작동하지 않습니다! 나는 그 (것)들을 거기에서 무엇이 일어날 것인지 단지 알기 위해 넣었다. .. –

0

첫 번째 문제는 UIKit에 이미 존재하는 클래스 UIView의 이름을 지정하는 것입니다. 이 문제를 해결하기 위해 @ Williham의 조언을 참조하십시오.

당신은 전용 속성 당 하나의 @synthesize 필요하고, 속성 이름은 인스턴스 변수 이름과 일치 할 때, 당신은 당신하는 .m 파일에서이 같은 작업을 수행해야한다 : 또한

@synthesize endLabel; 
@synthesize goButton; 
@synthesize textBox1; 
@synthesize textBox2; 

, 당신은있어 IBAction 메소드를 작동시키는 데 문제가 발생할 가능성이 있습니다. 대상 작업 연결에 대한 메서드를 사용하려면 반환 유형이 IBAction (올바른 값)이어야하고 보낸 사람을 나타내는 id 매개 변수를 받아 들여야합니다. 정규 메소드 서명은 다음과 같습니다 실제로 명시 적으로 같은 동작을 호출 할 수있는 다른 방법이있을 수 있습니다, 특히 이후를 호출하는 버튼에 묶여 아니에요 메서드 이름을 권하고 싶습니다

- (IBAction) goButtonClicked:(id)sender; 

. (예를 들어, 데스크톱 응용 프로그램을 작성하는 경우 키 등가 또는 메뉴 명령을 사용하여 동일한 작업을 수행 할 수 있습니다.)