Objective-C:预期出现类型错误

时间:2015-05-31 13:00:57

标签: ios objective-c types

我正在尝试使用来自Nick Kuh的书“iPhone App Development”的样式表的教程。样式表头文件抛出:

  

“预期类型”

错误我认为通常反映了一个循环问题。但是,在这种情况下,唯一的导入是Foundation.h。 (实现文件,顺便说一句,不会抛出任何错误,似乎没问题。)这是完整的头文件。

#import <Foundation/Foundation.h>

typedef enum : int {
    IDLabelTypeName = 0,
    IDLabelTypeBirthdayDate,
    IDLabelTypeDaysUntilBirthday,
    IDLabelTypeDaysUntilBirthdaySubText,
    IDLabelTypeLarge
}
IDLabelType;

@interface IDStyleSheet : NSObject
+(void)initStyles;

+(void)styleLabel:(UILabel *)label withType:(IDLabelType)labelType;//throws red error

+(void)styleTextView:(UITextView *)textView;//throws red error
+(void)styleRoundCorneredView:(UIView *)view;//throws red error


@end

有人能看出为什么会出现这些错误吗?

1 个答案:

答案 0 :(得分:5)

UILabelUITextView ...在UIKit框架中定义,因此您必须

#import <UIKit/UIKit.h>

(然后隐式导入Foundation)。你也可以使用 更现代的&#34;模块&#34;语法:

@import UIKit;