0

私は、iPhoneとiPad用に別々に2つのアプリデリゲートを持つユニバーサルアプリケーションを実行しています。のような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];
4

2 に答える 2

1

~ipadXIBファイル名を追加または末尾に追加する標準的な方法を使用して~iphone、XIBがそれぞれiPadまたはiPhone用であることを指定できます。

だからあなたは持っているかもしれません:

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.

于 2011-12-15T12:38:34.573 に答える
0

次のコードを使用する

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;

デリゲートにアクセスする必要があるときはいつでも。

于 2011-12-15T12:37:21.310 に答える