我真的不知道如何在不粘贴我所有代码的情况下解释这一点,但我会尝试一下。 “假设”我的 .hs 和 .ms 是准确的,我感觉我的 .xib 设置不正确,但我无法真正粘贴其中的代码。相反,我压缩了文件并上传了源代码。 (如果你足够勇敢,它就在这里:http://bit.ly/ZtDkGi)我得到了成功的构建,但我的模拟器的屏幕在应用程序启动后只是黑色的。
本质上,我必须手动添加一个 appDelegate 对象。我将类(class)设置为适当的类(class) - 但它仍然没有拉动。如果有人愿意提供帮助,那就太好了。
这是我的 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
最佳答案
在您的委托(delegate)中Test_TableViewAppDelegate
为什么要向窗口添加两次 View ?
// 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 的此 View 未使用任何 Nib 名称进行初始化
UIViewController *fvc = [[UIViewController alloc] init];
在您的委托(delegate)中初始化应该像这样
RootViewController *rootController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:rootController];
关于ios - AppDelegate和.xib没有正确实现,但是构建成功了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15274515/