Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Xcode 5-iOS-如何在没有脚本或XIB的Xcode中创建视图控制器,以及如何将其配置到AppDelegate中作为根视图_Ios_Objective C_Xcode_Uiwebview_Appdelegate - Fatal编程技术网

Xcode 5-iOS-如何在没有脚本或XIB的Xcode中创建视图控制器,以及如何将其配置到AppDelegate中作为根视图

Xcode 5-iOS-如何在没有脚本或XIB的Xcode中创建视图控制器,以及如何将其配置到AppDelegate中作为根视图,ios,objective-c,xcode,uiwebview,appdelegate,Ios,Objective C,Xcode,Uiwebview,Appdelegate,对,我从iOS开发人员那里休息了一下,我又回到了这个组合中,我遇到了以下问题: 我想通过编程方式创建一个带有嵌入式UIWebView的视图控制器,而不依赖任何xib或故事板,但我不记得如何让AppDelegate显示我的视图控制器 在所有文档中,我能找到的就是将下面的内容放在我的AppDelegate下 self.window = [[ViewController alloc] initWithNibName:@"blah" bundle: nil]; 但由于我没有任何与ViewControl

对,我从iOS开发人员那里休息了一下,我又回到了这个组合中,我遇到了以下问题:

我想通过编程方式创建一个带有嵌入式UIWebView的视图控制器,而不依赖任何xib或故事板,但我不记得如何让AppDelegate显示我的视图控制器

在所有文档中,我能找到的就是将下面的内容放在我的AppDelegate下

self.window = [[ViewController alloc] initWithNibName:@"blah" bundle: nil];
但由于我没有任何与ViewController文件关联的xib,这将是无用的

谁能让我回到正确的道路上来


感谢
AppDelegate.m中的:

CustomViewController *rootViewController = [CustomViewController new];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
CustomViewController.m
覆盖中:

- (void)loadView {
    //Configure your view
    self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    //other stuff
    [self.view setBackgroundColor:[UIColor redColor]];

    UIButton *button = /* alloc init etc. */
    [self.view addSubview:button];
}

类ViewController:UIViewController、UIPageViewControllerDataSource、CLLocationManagerDelegate、UITextFieldDelegate、UITableViewDataSource、UITableViewDelegate{ //创建位置管理器 让locationManager=CLLocationManager()


谢谢你的建议,我得到的只是一个黑屏(控制台中没有错误)我想添加我的代码集可能会有所帮助,给我一个mo…在AppDelegate下。m:
-(BOOL)应用程序:(UIApplication*)应用程序完成启动时使用选项:(NSDictionary*)启动选项{ViewController*rootViewController=[ViewController新建];self.window.rootViewController=rootViewController;[window makeKeyAndVisible];返回YES;}
在ViewController.m:
-(void)loadView{[super viewDidLoad];self.view=[[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds];webView=[[UIWebView alloc]initWithFrame:CGRectMake(0,0,320,480)];[webView加载请求:[nSurlRequestRequestWithURL:[NSurlUrlWithString:@”http://www.google.com“]]];[self.view addSubview:webView];}
对于格式问题表示歉意,我在SOMan上已经有一段时间了。您必须配置视图…这很正常。您是否编写了所有正确的代码?请参阅我的更新答案。例如,现在我将红色设置为背景。现在您看到您的视图了吗?;)这完全没有魔法。您只需定义自定义VC并将其设置为s
loadView
方法创建所有本应由XIB定义的组件。然后
viewDidLoad
应适当调整组件的大小和位置。对于XIB不能很好地表示的情况,这通常比使用XIB更简单。
//menu button
@IBOutlet weak var menu: UIBarButtonItem!

@IBOutlet weak var locationTextField: UITextField!{
    didSet {
        locationTextField.delegate = self
        locationTextField.text = ""
    }
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return globalSearchText.searchArrayLocation.count
}

func tableView(tableView: UITableView, performAction action: Selector, forRowAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) {
    locationTextField.text = globalSearchText.searchArrayLocation[indexPath.row]
}