我的应用程序在启动后立即崩溃

问题描述:

由于它在写入文档中,我的应用程序在启动后立即崩溃。我真的不知道该怎么做。谢谢你的帮助。这里是代码:我的应用程序在启动后立即崩溃

#import "ViewController.h" 
@import CoreLocation; 

@interface ViewController() <CLLocationManagerDelegate> 
@property (strong, nonatomic) CLLocationManager *locationManager; 
@property (weak, nonatomic) IBOutlet UILabel *location; 
@property (weak, nonatomic) IBOutlet UILabel *date; 
@end 

@implementation ViewController 
-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.locationManager = [[CLLocationManager alloc] init]; 
    self.locationManager.delegate = self; 

    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { 
     [self.locationManager requestWhenInUseAuthorization]; 
    } 

    [self.locationManager startUpdatingLocation]; 

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

    [dateFormatter setDateFormat:@"MMMM d, YYYY"]; 

    NSString *dateString = [dateFormatter stringFromDate:[NSDate date]]; 
    NSLog(@"%@", dateString); 
    self.date.text = (@"%@", dateString); 
} 

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{ 
    NSLog(@"%@", [locations lastObject]); 
    self.location.text = (@"%@", [locations lastObject]); 
} 

@end 

崩溃后,它显示了这个: http://i.stack.imgur.com/k0eVO.png

+1

你能告诉我们什么是在调试器打印? – Priyatham51 2015-04-05 10:19:42

+0

你看过http://stackoverflow.com/questions/24850128/ios-8-requestwheninuseauthorization-no-popup吗? – luk2302 2015-04-05 11:26:43

+0

挂钩lldb并检查后面的跟踪 – Wingzero 2015-04-05 13:20:41

您的代码是不完整的,你可以检查出来,并再次

你已经得到

@selector(requestWhenInUseAuthorization) 
发布

而你还没有设置功能requestWhenInUseAuthorization

您在下面的代码中放置了哪种方法。你已经把它放在viewDidLoad下面,但它不在任何方法内。检查你的代码正确

[self.locationManager startUpdatingLocation]; 

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

[dateFormatter setDateFormat:@"MMMM d, YYYY"]; 

NSString *dateString = [dateFormatter stringFromDate:[NSDate date]]; 
NSLog(@"%@", dateString); 
self.date.text = (@"%@", dateString); 
} 
+0

我也很困惑,但它只是一个格式问题,代码实际上是正确的,关于选择器:他没有定义它,他是在CLLocationManager上调用它,而不是自我 – luk2302 2015-04-05 11:25:08

+0

一切工作正常,但添加'self.date.text =(@“%@”,dateString);'线后它不再工作。我试图删除该行并再次运行,但没有任何工作。 – pettyBright 2015-04-05 11:41:15

+0

请删除此答案,因为它不包含任何相关内容 – luk2302 2015-04-05 11:48:08

适用异常断点在你的应用程序,然后再试一次。它会告诉你哪儿崩溃是