Xcode 通用应用程序模板,并覆盖 didFinishLaunchingWithOptions
我正在尝试使用基于窗口的应用程序的默认 Xcode 模板构建我的第一个通用 iOS 应用程序 - 并将设备系列设置为“通用”。 (我使用的是 Xcode 4,但我相信这些模板与以前版本的 Xcode 几乎相同。)
这将创建一个共享应用程序委托,以及适用于 iPhone 和 iPad 的特定应用程序委托。
由于 iPad 需要在应用程序启动时加载 SplitViewController,而 iPhone 需要加载 RootViewController(表视图) - 我决定尝试重写设备特定应用程序委托中的 didFinishLaunchingWithOptions 方法,对于 iPhone 如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[super application:application didFinishLaunchingWithOptions:launchOptions];
RootViewController *rootViewController = (RootViewController *)[_navController topViewController];
rootViewController.context = [self managedObjectContext];
[_window addSubview:_navController.view];
return YES;
}
但是,由于 Xcode 将设备特定的应用程序委托文件放在“iPhone”或“iPad”组中,因此我收到一条错误消息,指出“RootViewController.h”文件未找到...尽管尝试使用
#import "RootViewController.h"
以下方式 导入它:解决这个问题,还是我完全以错误的方式处理这个问题?我不想将“RootViewController.h”文件移到 iPhone 组中,因为我认为它也将在 iPad 上使用。
I'm attempting to build my first universal iOS app using the default Xcode templates for a window-based application - and setting the Device Family to "Universal". (I'm using Xcode 4, but I believe the templates are nearly identical for previous versions of Xcode.)
This creates a shared app delegate, along with specific app delegates for iPhone and iPad.
Since the iPad will need to load a SplitViewController when the app launches, and the iPhone will need to load the RootViewController (a table view) - I decided to try overriding the didFinishLaunchingWithOptions method in the device specific app delegates, like this for the iPhone:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[super application:application didFinishLaunchingWithOptions:launchOptions];
RootViewController *rootViewController = (RootViewController *)[_navController topViewController];
rootViewController.context = [self managedObjectContext];
[_window addSubview:_navController.view];
return YES;
}
However, since Xcode places the device specific app delegate files in an "iPhone" or "iPad" group, I get an error saying "RootViewController.h" file not found... despite trying to import it with:
#import "RootViewController.h"
Is there a way to resolve that, or am I going about this the wrong way altogether? I'd rather not move the "RootViewController.h" file into the iPhone group, since I think it will also be used on the iPad.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该遵循以下模型: http://www.kotancode.com/ 2011/04/05/ios-universal-apps/ 并且您应该导入“RootViewController_iPhone.h”
You should follow this model: http://www.kotancode.com/2011/04/05/ios-universal-apps/ and you should be importing "RootViewController_iPhone.h"