1

I created an IPhone app, then I had to convert it to IPad app. Now, I added a new Objective-C Class which includes XIB, .M and .H files. and I want that new XIB file to be shown on launch.

my new created files are named PhotoViewController. If I choose that file to be launched, emulator shows black screen. If I choose MainWindow-iPad file, I see Hello_SOAPViewController file launched. It is very weird.

How can I fix this mess? I want PhotoViewController to be started on launch.

Please take a look at the image below. You can see my project files and the project setup screen. enter image description here

4

2 回答 2

3

将应用程序转换为通用后:-

在此处输入图像描述

你已经创建了两个不同XIB的具有相同的自定义类。如下图:-

iphone->xib-选择文件所有者

在此处输入图像描述

现在为 Ipad ite 名称 PhotoViewController_ipad 创建新的 xib。现在只需打开它新创建的XIB->单击文件所有者--->看起来像:-

在此处输入图像描述

它的右侧自定义类空白放在那里PhotoviewCintroller

并将文件所有者连接到 View

在此处输入图像描述

现在你有两个 Xib,一个用于 Iphone,另一个用于 Ipad,现在你可以通过使用下面的编码来实现这一点:-

在 Delegate.m 文件中加载应用程序时,您需要检查它的 Iphone 或 Ipad:-

#define isiPhone (UI_USER_INTERFACE_IDIOM() == 0)?TRUE:FALSE

yourApplicationAppDelegate.h 类

#import <UIKit/UIKit.h>

@class PhotoViewController;

@interface yourApplicationAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) PhotoViewController *viewController;

@end

yourApplicationAppDelegate.m 类

#import "yourApplicationAppDelegate.h"

#import "PhotoViewController.h"
#define isiPhone  (UI_USER_INTERFACE_IDIOM() == 0)?TRUE:FALSE 
#define isiPhone5  ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE

@implementation yourApplicationAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.


        if (isiPhone) {

            if (isiPhone5) 
                {
                    self.viewController = [[PhotoViewController alloc] initWithNibName:@"PhotoViewController_iphone5" bundle:nil];     
                }
                else
                {
                    self.viewController = [[PhotoViewController alloc] initWithNibName:@"PhotoViewController_iphone" bundle:nil];
                }

        }else{
             self.viewController = [[PhotoViewController alloc] initWithNibName:@"PhotoViewController_ipad" bundle:nil];

        }



        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES;
    }

编辑 另一个想法是,如果您还为 iphone5 编码,那么您也可以 #define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE在我编辑答案时进行检查

于 2013-05-16T07:09:10.973 回答
2

1)在文件中分配PhotoViewControllerindidFinishLaunchingWithOptions方法。appDelegate

2) 设置self.window.rootViewController = PhotoViewController;

于 2013-05-16T07:11:08.847 回答