为什么我在Xcode的iPhone项目模板中看不到主要的功能实现?

时间:2023-01-13 18:10:56

That's strange, since apple says that there is somewhere an main function. But I really can't find any.

这很奇怪,因为苹果说有某个主要功能。但我真的找不到任何东西。

It should look somehow like this:

它应该看起来像这样:

#import <UIKit/UIKit.h>

int main(int argc, char *argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

What file is that where I can see it? Is it hidden?

我能看到什么文件?它隐藏了吗?

3 个解决方案

#1


It's always in the Other Sources group of your pregenerated project layout.

它始终位于预生成项目布局的“其他来源”组中。

main.m http://lhunath.lyndir.com/stuff/main.png

#2


If you can't find it, you can always just create a new code file and copy in this function. When the project compiles, it will only allow you to have one main function, so if it disappeared at some point, you can just re-add it.

如果找不到它,您可以随时创建一个新的代码文件并复制到此函数中。当项目编译时,它只允许你有一个主函数,所以如果它在某个时刻消失了,你可以重新添加它。

Alternately, you might have picked a project type that does not compile down to an executable. Not sure if/what these might be for iphone, but normally a "library" project will not have a main function.

或者,您可能选择了不能编译为可执行文件的项目类型。不确定这些是否适用于iphone,但通常“库”项目不具备主要功能。

#3


Expand "Other Sources" in the Groups and Files section and the file is named main.m .

展开“组和文件”部分中的“其他来源”,该文件名为main.m。

#1


It's always in the Other Sources group of your pregenerated project layout.

它始终位于预生成项目布局的“其他来源”组中。

main.m http://lhunath.lyndir.com/stuff/main.png

#2


If you can't find it, you can always just create a new code file and copy in this function. When the project compiles, it will only allow you to have one main function, so if it disappeared at some point, you can just re-add it.

如果找不到它,您可以随时创建一个新的代码文件并复制到此函数中。当项目编译时,它只允许你有一个主函数,所以如果它在某个时刻消失了,你可以重新添加它。

Alternately, you might have picked a project type that does not compile down to an executable. Not sure if/what these might be for iphone, but normally a "library" project will not have a main function.

或者,您可能选择了不能编译为可执行文件的项目类型。不确定这些是否适用于iphone,但通常“库”项目不具备主要功能。

#3


Expand "Other Sources" in the Groups and Files section and the file is named main.m .

展开“组和文件”部分中的“其他来源”,该文件名为main.m。