Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AppDelegate和.xib未正确实现,但生成成功吗?_Ios_Xcode_Uitableview_Delegates_Xib - Fatal编程技术网

Ios AppDelegate和.xib未正确实现,但生成成功吗?

Ios AppDelegate和.xib未正确实现,但生成成功吗?,ios,xcode,uitableview,delegates,xib,Ios,Xcode,Uitableview,Delegates,Xib,我真的不知道如何在不粘贴所有代码的情况下解释这一点,但我会试一试。“假设”我的.hs和.ms是准确的,我感觉我的.xib设置不正确,但我不能从中粘贴代码。相反,我压缩了文件并上传了源代码。(如果你足够勇敢,它就在这里:)我得到了一个成功的构建,但我的模拟器的屏幕在应用程序启动后是黑色的 本质上,我必须手动添加一个appDelegate对象。我将该类设置为适当的类,但它仍然不起作用。如果有人愿意帮忙,那就太好了 这是我的Test_TableViewAppDelegate.h #import <

我真的不知道如何在不粘贴所有代码的情况下解释这一点,但我会试一试。“假设”我的.hs和.ms是准确的,我感觉我的.xib设置不正确,但我不能从中粘贴代码。相反,我压缩了文件并上传了源代码。(如果你足够勇敢,它就在这里:)我得到了一个成功的构建,但我的模拟器的屏幕在应用程序启动后是黑色的

本质上,我必须手动添加一个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
@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
最后但并非最不重要的是main.m(我认为这可能也是一个问题)


提前谢谢。我将非常感谢:d

在您的委托中
测试\u 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];

我相信你得到一个黑屏的原因是你没有正确地分配和初始化你的导航控制器

相反,您应该尝试以下代码:

- (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;
}

希望这能奏效

好的。。。它把黑色变成了绿色。。。但我仍然无法看到我的阵列:)至少我正在进步!有什么建议吗?好的,我刚刚把你的代码添加到我的代码中,并在上面编辑了它。我在导航栏下变绿了:D建议?同样,你可以下载我的全部源代码,如果可以的话,看看我做错了什么。它真的很小。谢谢好的,我去掉了那两行。在我的导航控制器下仍然是一个绿色的窗口。我不应该看到绿色上方的UITableView吗?您应该使用界面中的nib名称初始化
UIViewController
。我的答案是,您应该使用界面中创建的ViewController在哪个文件中?RootViewController.m?如果您的viewController名称是RootViewController,那么您应该在委托中声明该名称,并使用该名称添加到navigationController
RootViewController *rootController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:rootController];
- (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;
}