“对象”未声明<在此函数中首次使用>

发布于 2024-09-03 04:16:12 字数 3195 浏览 4 评论 0原文

我正在我的 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

ma​​in.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坏尐絯℡ 2024-09-10 04:16:12

标头声明了 textview(小写),但实现引用了 textView(驼峰式)。标识符区分大小写。

The header declares textview (lowercase), but the implementation refers to textView (camelCase). Identifiers are case-sensitive.

习惯成性 2024-09-10 04:16:12

它是 .h 中的 textview,但 .m 中的 textView

it's textview in .h but textView in .m

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文