[英]After creating a project on Xcode, i deleted the viewController that comes by default and created a new one. But the project does not run
I created a project in Xcode and deleted the viewController file that comes by default in it. 我在Xcode中创建了一个项目,并删除了其中默认包含的viewController文件。 I added a new file(objective-c class) and added some controls in its viewDidLoad and run the project but it does not seem to work,the view it shows is blank.
我添加了一个新文件(objective-c类),并在其viewDidLoad中添加了一些控件并运行该项目,但它似乎不起作用,显示的视图为空白。 Is there any setting to be made?
有什么需要设置的吗?
When you say deleted the viewController file that comes by default in it.
当您说
deleted the viewController file that comes by default in it.
, that means that you have chosen application type other than Empty Application
. ,表示您选择的应用程序类型不是
Empty Application
。 That means most probably you might have chosen a Single view Application
, as the defaultViewcontroller file will be provided with SingleView application( means with Storyboards by defaults on Xcode 5+). 这意味着您很可能已经选择了“
Single view Application
,因为SingleView应用程序将提供defaultViewcontroller文件(这意味着Xcode 5+上默认情况下带有Storyboard)。
So even if you have deleted the application, you can just 因此,即使您删除了该应用程序,也可以
UIViewController
), UIViewController
继承), myViewController
) myViewController
) #import "myViewController.h"
) #import "myViewController.h"
) myViewController *vc = [myViewController alloc]init]
) myViewController *vc = [myViewController alloc]init]
) If you want to add buttons or anything else, 如果您想添加按钮或其他内容,
myViewController
myViewController
创建对象 add them to SubViews. 将它们添加到SubViews。
If you are using storyBoards, then 如果您使用的是StoryBoards,则
myViewController
myViewController
myViewController
myViewController
appDelegate
file. appDelegate
文件中的任何内容。 hope that gives you the overview. 希望能给您概述。
You have to set mainviewcontroller from didFinishLaunchingWithOptions method of appdelegate.m file. 您必须从appdelegate.m文件的didFinishLaunchingWithOptions方法设置mainviewcontroller。
as below 如下
#import "Yourviewcontroller.h"
and in didFinishLaunchingWithOptions method:- 在didFinishLaunchingWithOptions方法中:
self.viewController = [[YourViewControoler alloc] initWithNibName:@"Your xib file" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.navigationController;
I hope this will help you. 我希望这能帮到您。
Yes. 是。 You have modify the AppDelegate file.
您已修改AppDelegate文件。
Suppose you add the new controller that name is DashboardViewController. 假设您添加了名为DashboardViewController的新控制器。
DashboardViewController.h DashboardViewController.h
#import <UIKit/UIKit.h>
@class DashboardViewController;
@property (nonatomic,strong) DashboardViewController *viewController;
***DashboardViewController.m***
@synthesize viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[DashboardViewController alloc] initWithNibName:@"DashboardViewController" bundle:nil];
self.window.rootViewController = self.viewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.