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

根视图控制器.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 ,为什么您向窗口添加两次视图?

// 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 的这个视图没有用任何 nib 名称初始化

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 回答