objective-c - 为什么它不能从主文件中识别头文件中的@properties?

标签 objective-c xcode properties syntax-error

UIView.h

#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

最佳答案

@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

关于objective-c - 为什么它不能从主文件中识别头文件中的@properties?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1116690/

相关文章:

ios - 如何检测照片库中的图像是iPhone相机拍摄的还是导入的

ios - 我们是否应该在应用程序启动期间每次都注册 iOS 推送通知?

ios - 项目选择器未显示在 xcode 中

javascript - getComputedStyle 对象包含方法?

Javascript - 为元素分配新 ID

objective-c - CAMediaTimingFunction 具有 3 个 {0.0f} 控制点?

ios - 如何在 Objective-C 和 Swift 中等待

ios - 如何从我的自定义正在进行的调用 UI 结束 callkit 上的调用 session ?

c# - Xamarin.Forms 属性未保存在 Android 上的 Release 中

objective-c - 使用 NSLog 使用枚举数据类型的 token