0

すべてのコードを貼り付けずにこれを説明する方法は本当にわかりませんが、試してみてください。.hsと.msが正確であると「仮定」すると、.xibが正しく設定されていないように感じますが、そこからコードを実際に貼り付けることはできません。代わりに、ファイルを圧縮してソースコードをアップロードしました。(十分に勇気がある場合は、ここにあります:http: //bit.ly/ZtDkGi)ビルドは成功していますが、アプリの起動後、エミュレーターの画面が真っ暗になっています。

基本的に、appDelegateオブジェクトを手動で追加する必要がありました。クラスを適切なクラスに設定しましたが、それでもプルしません。誰かが親切に助けてくれるなら、それは素晴らしいことです。

これが私のTest_TableViewAppDelegate.hです

#import <UIKit/UIKit.h>
@interface Test_TableViewAppDelegate : NSObject <UIApplicationDelegate>
{

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;

@end

これが私の新しいTest_TableViewAppDelegate.mです

#import "Test_TableViewAppDelegate.h"

@implementation Test_TableViewAppDelegate

@synthesize window=_window;
@synthesize navController=_navController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//self.window.backgroundColor = [UIColor whiteColor];

UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.backgroundColor = [UIColor greenColor];
self.window = window;

UIViewController *fvc = [[UIViewController alloc] init];

UIViewController *rootController = [[UIViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:rootController];

//UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:fvc];
self.navController = nc;

//[self.window addSubview: nc.view];
//[self.window makeKeyAndVisible];


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

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UITableViewController {
NSMutableArray *petsArray;

}

@end

RootViewController.m

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

最後になりましたが、main.m(これも問題になる可能性があると思います)

#import "Test_TableViewAppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([Test_TableViewAppDelegate class]));
}
}

前もって感謝します。よろしくお願いします:D

4

2 に答える 2

1

デリゲートでTest_TableViewAppDelegate 、ウィンドウにビューを2回追加するのはなぜですか?

// you could remove these two lines
[self.window addSubview: nc.view];
[self.window makeKeyAndVisible];  

//keep these two lines
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];

そして、あなたがnavigationControllerに追加しているこのビューは、ペン先名で初期化されていません

UIViewController *fvc = [[UIViewController alloc] init];

デリゲートでは、初期化は代わりにこのようにする必要があります

RootViewController *rootController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:rootController];
于 2013-03-07T15:18:09.957 に答える
0

黒い画面が表示される理由は、ナビゲーション コントローラーの割り当てと初期化が適切に行われていないためだと思います。

代わりに、次のコードを試してください。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{
    // create the base window
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    window.backgroundColor = [UIColor greenColor];
    self.window = window;

    [window release];

    // this is the home page from the user's perspective

    FirstViewController *fvc = [[FirstViewController alloc] init];

    UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:fvc];
    self.navigationController = nc;

    [fvc release];
    [nc release];

    // show them
    [self.window addSubview: nc.view];
    [self.window makeKeyAndVisible];


    return YES;
}

これがうまくいくことを願っています!

于 2013-03-07T15:20:54.057 に答える