Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.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根控制器在启动时出错_Ios_Debugging_Viewcontroller - Fatal编程技术网

iOS根控制器在启动时出错

iOS根控制器在启动时出错,ios,debugging,viewcontroller,Ios,Debugging,Viewcontroller,我在尝试测试运行应用程序时收到以下错误代码 Application windows are expected to have a root view controller at the end of application launch 该应用程序作为裸壳应用程序运行良好(例如,未实现任何功能),但一旦我向ViewController.m添加了功能,它就开始生成此错误 m包含 // // BattTimeViewController.m // BattTime // // Created

我在尝试测试运行应用程序时收到以下错误代码

Application windows are expected to have a root view controller at the end of application launch
该应用程序作为裸壳应用程序运行良好(例如,未实现任何功能),但一旦我向ViewController.m添加了功能,它就开始生成此错误

m包含

//
//  BattTimeViewController.m
//  BattTime
//
//  Created by James Krawczyk on 09/03/2012.
//  Copyright (c) 2012 James Krawczyk. All rights reserved.
//

#import "BattTimeViewController.h"

@interface BattTimeViewController ()

@end

@implementation BattTimeViewController
@synthesize resDisplay;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setResDisplay:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (void)batteryStatus
{
    // Get current date time

    datetrack = [NSDate date];

    // Instantiate a NSDateFormatter

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    // Set the dateFormatter format

    //[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

    // or this format to show day of the week Sat,11-12-2011 23:27:09

    [dateFormatter setDateFormat:@"HH:mm:ss"];

    // Get the date time in NSString

    NSString *dateInStringFormated = [dateFormatter stringFromDate:datetrack];

    NSLog(@"%@", dateInStringFormated);

    // Release the dateFormatter

    //[dateFormatter release]; 


    NSArray *batteryStatus = [NSArray arrayWithObjects: 
                              @"Battery status is unknown.", 
                              @"Battery is in use.", 
                              @"Battery is charging.", 
                              @"Battery is fully charged.", nil];

    if ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateUnknown)
    {
        [resDisplay setText:[batteryStatus objectAtIndex:0]];  
        NSLog(@"%@", [batteryStatus objectAtIndex:0]);
    }
    else
    {   
        NSString *msg = [NSString stringWithFormat:
                         @"Battery charge level: %0.2f%%\n%@", [[UIDevice currentDevice] batteryLevel] * 100, dateInStringFormated ];
        [resDisplay setText:msg];  
        NSLog(@"%@", msg);
    }
}

- (void)loadView 
{

    // Enable monitoring of battery status
    [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

    // Print current status
    [self batteryStatus];

    // Request to be notified when battery charge or state changes
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryStatus) name:UIDeviceBatteryLevelDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryStatus) name:UIDeviceBatteryStateDidChangeNotification object:nil];

}

- (void)dealloc 
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];

}
@end
ViewController.h是

//
//  BattTimeViewController.h
//  BattTime
//
//  Created by James Krawczyk on 09/03/2012.
//  Copyright (c) 2012 James Krawczyk. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface BattTimeViewController : UIViewController
{
        NSDate  *datetrack;
}

@property (weak, nonatomic) IBOutlet UILabel *resDisplay;




@end
//
//BattTimeViewController.h
//战斗时间
//
//James Krawczyk于2012年3月9日创作。
//版权所有(c)2012詹姆斯·克劳茨克。版权所有。
//
#进口
@接口BattTimeViewController:UIViewController
{
NSDate*日期跟踪;
}
@属性(弱,非原子)IBUILabel*resDisplay;
@结束
我已经检查了一些其他问题,也检查了主要问题。m也是,但据我所知,那里的一切看起来都很好。不过,就像我说的,在我添加这些函数之前,它运行得很好

最后,main.m是

//
//  main.m
//  BattTime
//
//  Created by James Krawczyk on 09/03/2012.
//  Copyright (c) 2012 James Krawczyk. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "BattTimeAppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([BattTimeAppDelegate class]));
    }
}
//
//main.m
//战斗时间
//
//James Krawczyk于2012年3月9日创作。
//版权所有(c)2012詹姆斯·克劳茨克。版权所有。
//
#进口
#导入“BattTimeAppDelegate.h”
int main(int argc,char*argv[])
{
@自动释放池{
返回UIApplicationMain(argc、argv、nil、NSStringFromClass([BattTimeAppDelegate类]);
}
}

我不知道您的BattTimeAppDelegate是否正在使用NIB、情节提要或(受虐)代码来创建窗口,但此错误意味着您的UIWindow实例没有rootViewController。如果使用NIB或SB,则需要将窗口的rootViewController链接到BattTimeViewController。如果使用代码(请不要),则需要执行类似“window.rootViewController=aHandMadeBattTimeViewController;”的操作。

它使用的是故事板格式。但是我如何链接它?因为我假设它已经链接了,因为它以前工作过。您的VC必须是“初始视图控制器”(在属性检查器中),并且您的AppDelegate必须具有强“UIWindow*window”属性。编辑:你的SB必须是你信息中的“主要情节提要”。我已经检查了所有这些,它们都是正确的。只有当BattTimeViewController.mUpdate中的代码:刚刚使用clean project从头开始,并且代码生成相同的错误时,才会发生此更改。已解决。我用作模板的代码使用了viewLoad,但由于viewLoad移动了视图控制器,我需要将该代码移动到viewDidLoad。