“对象”未声明<在此函数中首次使用>在此函数中首次使用>
我正在我的 Windows 7 机器上使用 Winchain 进行开发。这是我的代码:
iPhoneTest.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface iPhoneTest : UIApplication {
UITextView *textview;
UIView *mainView;
}
@end
iPhoneTest.m
#import "iPhoneTest.h"
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
@implementation iPhoneTest
-(void)applicationDidFinishLaunching:(id)unused {
UIWindow *window;
struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
rect.origin.x = rect.origin.y = 0.0f;
window = [[UIWindow alloc] initWithContentRect: rect];
mainView = [[UIView alloc] initWithFrame: rect];
textView = [[UITextView alloc] init];
[textView setEditable:YES];
[textView setTextSize:14];
[window orderFront: self];
[window makeKey: self];
[window _setHidden: NO];
[window setContentView: mainView];
[mainView addSubview:textView];
[textView setText:@"Hello World"];
}
@end
main.m
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "iPhoneTest.h"
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int ret = UIApplicationMain(argc, argv, [iPhoneTest class]);
[pool release];
return ret;
}
Makefile
INFOPLIST_FILE=Info.plist
SOURCES=\
main.m \
iPhoneTest.m
CC=/usr/local/bin/arm-apple-darwin-gcc
CFLAGS=-g -O2 -Wall
LD=$(CC)
LDFLAGS=-lobjc -framework CoreFoundation -framework Foundation -framework UIKit -framework LayerKit
PRODUCT_NAME=iPhoneTest
SRCROOT=/iphone-apps/iPhoneTest
WRAPPER_NAME=$(PRODUCT_NAME).app
EXECUTABLE_NAME=$(PRODUCT_NAME)
SOURCES_ABS=$(addprefix $(SRCROOT)/,$(SOURCES))
INFOPLIST_ABS=$(addprefix $(SRCROOT)/,$(INFOPLIST_FILE))
OBJECTS=\
$(patsubst %.c,%.o,$(filter %.c,$(SOURCES))) \
$(patsubst %.cc,%.o,$(filter %.cc,$(SOURCES))) \
$(patsubst %.cpp,%.o,$(filter %.cpp,$(SOURCES))) \
$(patsubst %.m,%.o,$(filter %.m,$(SOURCES))) \
$(patsubst %.mm,%.o,$(filter %.mm,$(SOURCES)))
OBJECTS_ABS=$(addprefix $(CONFIGURATION_TEMP_DIR)/,$(OBJECTS))
APP_ABS=$(BUILT_PRODUCTS_DIR)/$(WRAPPER_NAME)
PRODUCT_ABS=$(APP_ABS)/$(EXECUTABLE_NAME)
all: $(PRODUCT_ABS)
$(PRODUCT_ABS): $(APP_ABS) $(OBJECTS_ABS)
$(LD) $(LDFLAGS) -o $(PRODUCT_ABS) $(OBJECTS_ABS)
$(APP_ABS): $(INFOPLIST_ABS)
mkdir -p $(APP_ABS)
cp $(INFOPLIST_ABS) $(APP_ABS)/
$(CONFIGURATION_TEMP_DIR)/%.o: $(SRCROOT)/%.m
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
clean:
echo rm -f $(OBJECTS_ABS)
echo rm -rf $(APP_ABS)
当我尝试使用 make< 编译它时/code>,我明白
iPhoneTest.m: In function '-[iPhoneTest applicationDidFinishLaunching:]'
iPhoneTest.m:15: error: 'textView' undeclared <first use in this function>
iPhoneTest.m:15: error: <Each undeclared identifier is reported only once for each function it appears in>
有人能发现问题吗?
I am using Winchain to develop on my Windows 7 machine. Here is my code:
iPhoneTest.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface iPhoneTest : UIApplication {
UITextView *textview;
UIView *mainView;
}
@end
iPhoneTest.m
#import "iPhoneTest.h"
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
@implementation iPhoneTest
-(void)applicationDidFinishLaunching:(id)unused {
UIWindow *window;
struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
rect.origin.x = rect.origin.y = 0.0f;
window = [[UIWindow alloc] initWithContentRect: rect];
mainView = [[UIView alloc] initWithFrame: rect];
textView = [[UITextView alloc] init];
[textView setEditable:YES];
[textView setTextSize:14];
[window orderFront: self];
[window makeKey: self];
[window _setHidden: NO];
[window setContentView: mainView];
[mainView addSubview:textView];
[textView setText:@"Hello World"];
}
@end
main.m
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "iPhoneTest.h"
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int ret = UIApplicationMain(argc, argv, [iPhoneTest class]);
[pool release];
return ret;
}
Makefile
INFOPLIST_FILE=Info.plist
SOURCES=\
main.m \
iPhoneTest.m
CC=/usr/local/bin/arm-apple-darwin-gcc
CFLAGS=-g -O2 -Wall
LD=$(CC)
LDFLAGS=-lobjc -framework CoreFoundation -framework Foundation -framework UIKit -framework LayerKit
PRODUCT_NAME=iPhoneTest
SRCROOT=/iphone-apps/iPhoneTest
WRAPPER_NAME=$(PRODUCT_NAME).app
EXECUTABLE_NAME=$(PRODUCT_NAME)
SOURCES_ABS=$(addprefix $(SRCROOT)/,$(SOURCES))
INFOPLIST_ABS=$(addprefix $(SRCROOT)/,$(INFOPLIST_FILE))
OBJECTS=\
$(patsubst %.c,%.o,$(filter %.c,$(SOURCES))) \
$(patsubst %.cc,%.o,$(filter %.cc,$(SOURCES))) \
$(patsubst %.cpp,%.o,$(filter %.cpp,$(SOURCES))) \
$(patsubst %.m,%.o,$(filter %.m,$(SOURCES))) \
$(patsubst %.mm,%.o,$(filter %.mm,$(SOURCES)))
OBJECTS_ABS=$(addprefix $(CONFIGURATION_TEMP_DIR)/,$(OBJECTS))
APP_ABS=$(BUILT_PRODUCTS_DIR)/$(WRAPPER_NAME)
PRODUCT_ABS=$(APP_ABS)/$(EXECUTABLE_NAME)
all: $(PRODUCT_ABS)
$(PRODUCT_ABS): $(APP_ABS) $(OBJECTS_ABS)
$(LD) $(LDFLAGS) -o $(PRODUCT_ABS) $(OBJECTS_ABS)
$(APP_ABS): $(INFOPLIST_ABS)
mkdir -p $(APP_ABS)
cp $(INFOPLIST_ABS) $(APP_ABS)/
$(CONFIGURATION_TEMP_DIR)/%.o: $(SRCROOT)/%.m
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) -c lt; -o $@
clean:
echo rm -f $(OBJECTS_ABS)
echo rm -rf $(APP_ABS)
When I try to compile it with make
, I get
iPhoneTest.m: In function '-[iPhoneTest applicationDidFinishLaunching:]'
iPhoneTest.m:15: error: 'textView' undeclared <first use in this function>
iPhoneTest.m:15: error: <Each undeclared identifier is reported only once for each function it appears in>
Can anyone spot the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标头声明了
textview
(小写),但实现引用了textView
(驼峰式)。标识符区分大小写。The header declares
textview
(lowercase), but the implementation refers totextView
(camelCase). Identifiers are case-sensitive.它是
.h
中的textview
,但.m
中的textView
it's
textview
in.h
buttextView
in.m