通用应用程序的单一应用程序委托
我正在做一个通用应用程序,它有 2 个分别适用于 iPhone 和 iPad 的应用程序代表。我可以使用设置为 yes 的 bool 值(例如 BOOL isiPhone
)和方法 +(AppDelegate*)instance;
来检查单个应用程序委托中的设备吗?那么如何启动不同的视图呢?我得到了一些像这样的代码片段
@interface AppDelegate : NSObject <UIApplicationDelegate, NSFetchedResultsControllerDelegate> {
UIWindow* window;
BOOL isiPhone;
@property (nonatomic, retain) IBOutlet UIWindow* window;
@property (nonatomic, assign) BOOL isiPhone;
+ (AppDelegate*)instance;
@end
在应用程序的 App Delegate m 文件中:
@synthesize m_ForIPhone;
self.MapVC = [[MapViewController alloc] initWithNibName:(self.isiPhone ? @"MapView" : @"MapView@pad") bundle:nil];
self.DetailVC = [[DetailViewController alloc] initWithNibName:self.isiPhone ? @"DetailView" : @"DetailView@pad" bundle:nil];
self.AboutVC = [[AboutViewController alloc] initWithNibName:self.isiPhone ? @"AboutView" : @"AboutView@pad" bundle:nil];
I am doing a universal application which has 2 app delegates separately for iPhone and iPad. Can I check the device in a single app delegate using a bool value set to yes something like BOOL isiPhone
and the method +(AppDelegate*)instance;
. Then how can I launch different views? I got some code snippet like this
@interface AppDelegate : NSObject <UIApplicationDelegate, NSFetchedResultsControllerDelegate> {
UIWindow* window;
BOOL isiPhone;
@property (nonatomic, retain) IBOutlet UIWindow* window;
@property (nonatomic, assign) BOOL isiPhone;
+ (AppDelegate*)instance;
@end
And in the Application's App Delegate m file:
@synthesize m_ForIPhone;
self.MapVC = [[MapViewController alloc] initWithNibName:(self.isiPhone ? @"MapView" : @"MapView@pad") bundle:nil];
self.DetailVC = [[DetailViewController alloc] initWithNibName:self.isiPhone ? @"DetailView" : @"DetailView@pad" bundle:nil];
self.AboutVC = [[AboutViewController alloc] initWithNibName:self.isiPhone ? @"AboutView" : @"AboutView@pad" bundle:nil];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用标准方法将
~ipad
或~iphone
附加到 XIB 文件名的末尾,以分别指定 XIB 适用于 iPad 或 iPhone。所以你可能会:
它会选择适合该平台的最具体的一个,因此在 iPhone 上运行时,您将加载
MapView.xib
,而在 iPad 上,它将加载MapView~ipad .xib
。You could just use the standard way of appending
~ipad
or~iphone
to the end of your XIB filenames to specify that XIB is for iPad or iPhone respectively.So you might have:
It will pick the most specific one for that platform, so running on the iPhone you'll get
MapView.xib
being loaded whilst on the iPad it will loadMapView~ipad.xib
.请使用以下代码。
每当您需要访问委托时,
Use the Following Code
whenever you are required to access to the delegate.