如何从现有的iPhone项目中删除故事板

时间:2014-07-04 08:47:28

标签: ios objective-c uinavigationcontroller storyboard

我是iPhone编程的新手,现在面临故事板的问题。我想从应用程序中删除storyboard并以编程方式从appDelegate调用视图控制器。我怎么能做到这一点?

以下是appDelegate中的代码:

FirstViewController *firstView = [[FirstViewController alloc] init];
self.window.rootViewController = signInView;
return YES;

仍显示黑屏。请帮我。感谢。

8 个答案:

答案 0 :(得分:1)

删除主故事板文件基本名称。这是.plist。

enter image description here

答案 1 :(得分:0)

它显示黑屏的原因是因为FirstViewController课程中没有配置任何内容。尝试在firstView.view.backgroundColor = [UIColor greenColor];之前设置return YES',然后您会看到FirstViewController实际上正在加载;除了您在init课程的FirstViewController方法中所执行的操作之外,它没有任何配置。

老实说,在故事板之外配置ViewControllers对初学者来说并不好玩。我不知道你为什么要这样做,但你的选择是使用.nibs或手动添加所有内容。我鼓励你不要删除你的故事板,但如果必须,你的代码就可以了。只需删除故事板文件,或者更好的是,在你决定回到它之前不要使用它,因为它是一个更好的主意。

答案 2 :(得分:0)

您是否初始化了窗口并将其设为关键?

以下是我的某个应用的实现:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[DDHDemoViewController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;

答案 3 :(得分:0)

也许您必须在项目设置中删除主界面。

答案 4 :(得分:0)

以下是我正在做的步骤。

  1. 创建一个空项目或如果您已经没有后顾之忧,只需从@trick建议中删除plist中的StoryBoard条目。

  2. 从项目中删除MainStoryBorad文件

  3. 使用名为" MyViewController"

  4. 的XIB文件创建新的UIViewController
  5. 在AppDelegate.h中添加@property for New Controller" MyViewController"

  6. 在AppDelegate.m中以这种方式更新didFinishLaunchingWithOptions方法。


  7. -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
    (NSDictionary *)launchOptions
    {
                self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
    
                 MyViewController *viewController = [[MyViewController alloc]     initWithNibName:@"MyViewController" bundle:nil];
                 UINavigationController *nav = [[UINavigationController alloc]  initWithRootViewController:viewController];
                 self.window.rootViewController = nav;
    
                 [self.window makeKeyAndVisible];
    
                 return YES;
            }
    

答案 5 :(得分:0)

如果你的应用程序没有那么复杂的大量UI视图控制器,我认为使用故事板比使用xib更好。 如果要从项目中删除故事板并使用nib与开发一起使用,请执行以下链接的步骤:

http://www.wastedpotential.com/create-an-ios-app-without-storyboards-in-xcode-5/

答案 6 :(得分:0)

从项目中删除MainStoryBorad文件。

从info.plist文件中删除MainStroryBoard密钥。

从项目设置中清除MainInterface选项。

使用名为" MyViewController"

的XIB文件创建新的UIViewController

在你的AppDelegate.h中添加@property for New Controller" MyViewController"

以这种方式在你的AppDelegate.m更新didFinishLaunchingWithOptions方法。

- (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {             self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

         MyViewController *viewController = [[MyViewController alloc]     initWithNibName:@"MyViewController" bundle:nil];
         UINavigationController *nav = [[UINavigationController alloc]  initWithRootViewController:viewController];
         self.window.rootViewController = nav;

         [self.window makeKeyAndVisible];

         return YES;
    }

答案 7 :(得分:0)

请查看以下链接并查看物品.. 1. Info.plist或一般信息 - >删除主界面 2.检查.xib连接 - >添加了自定义类,在.xib中查看连接

https://github.com/sunilhts/RemoveDefaultStoryBoard