Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.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 在启动时加载新的.nib_Ios_Objective C_Xcode - Fatal编程技术网

Ios 在启动时加载新的.nib

Ios 在启动时加载新的.nib,ios,objective-c,xcode,Ios,Objective C,Xcode,在我的项目中,我添加了一个新的Cocoa Touch类及其.nib文件。我称之为文件ViewController。因此,我的项目a中添加了三个文件 ViewController.h、ViewController.m和ViewController.nib。现在我的项目已经有了一个默认的.nib文件,我删除了它。然后我转到属性设置并将主界面部分更改为我的新nib文件的名称,即ViewController.xib。然后,我向我的nib文件添加了一些内容,但是在运行模拟器时,我的nib文件内容不会显示出

在我的项目中,我添加了一个新的Cocoa Touch类及其.nib文件。我称之为文件ViewController。因此,我的项目a中添加了三个文件 ViewController.h、ViewController.m和ViewController.nib。现在我的项目已经有了一个默认的.nib文件,我删除了它。然后我转到属性设置并将主界面部分更改为我的新nib文件的名称,即ViewController.xib。然后,我向我的nib文件添加了一些内容,但是在运行模拟器时,我的nib文件内容不会显示出来。任何关于我可能做错什么的建议。这些是项目中当前的文件。我使用的是Xcode 6

文件名:ViewController.h

文件名:AppDelegate.h

文件名:main.m


我不确定这是否是一个错误。有关于如何解决此问题的建议吗?

请在应用程序IDFinishLaunching中尝试以下方法

self.window = [[UIWindow alloc] initWithFrame:
[[UIScreen mainScreen] bounds]]; 
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] 
 initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;

您需要将ViewController设置为AppDelegate.m中的rootViewController。首先需要导入ViewController.h,然后:

self.window.rootViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    return YES;

在从scrtach重建之前,您是否从模拟器或设备中删除了应用程序?通常情况下,时间.xib的更改只有在您这样做后才会生效。

关于self.window.backgroundColor=[UIColor whiteColor];[self.window makeKeyAndVisible];返回YES?第一个设置颜色为白色,你可以这样做,如果你想,但你的viewController将覆盖整个屏幕,对吗?最后一行把它带到前面。你可以把它们保存在你的代码里。今天晚些时候我会尝试一下并发回。谢谢
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (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];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}
Application windows are expected to have a root view controller at the end of application launch
self.window = [[UIWindow alloc] initWithFrame:
[[UIScreen mainScreen] bounds]]; 
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] 
 initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
self.window.rootViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    return YES;