通用应用程序的单一应用程序委托

发布于 2024-12-21 12:10:31 字数 940 浏览 5 评论 0原文

我正在做一个通用应用程序,它有 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 技术交流群。

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

发布评论

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

评论(2

可爱暴击 2024-12-28 12:10:31

您可以使用标准方法将 ~ipad~iphone 附加到 XIB 文件名的末尾,以分别指定 XIB 适用于 iPad 或 iPhone。

所以你可能会:

MapView.xib
MapView~ipad.xib

DetailView.xib
DetailView~ipad.xib

AboutView.xib
AboutView~ipad.xib

它会选择适合该平台的最具体的一个,因此在 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:

MapView.xib
MapView~ipad.xib

DetailView.xib
DetailView~ipad.xib

AboutView.xib
AboutView~ipad.xib

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 load MapView~ipad.xib.

意中人 2024-12-28 12:10:31

请使用以下代码。

id<UIApplicationDelegate> delegate = [[UIApplication sharedApplication] delegate]; 

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
AppDelegate_iPad *appDelegate = (AppDelegate_iPad *) delegate;

else
AppDelegate_iPhone *appDelegate = (AppDelegate_iPhone *) delegate;

每当您需要访问委托时,

Use the Following Code

id<UIApplicationDelegate> delegate = [[UIApplication sharedApplication] delegate]; 

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
AppDelegate_iPad *appDelegate = (AppDelegate_iPad *) delegate;

else
AppDelegate_iPhone *appDelegate = (AppDelegate_iPhone *) delegate;

whenever you are required to access to the delegate.

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