ios – Xcode:参数无效

ios – Xcode:参数无效,第1张

概述在执行日期选择器之后,我在 Xcode中遇到一个非常令人沮丧的错误.调试器中的错误是:“由于未捕获异常终止应用程序”NSInternalInconsistencyException“,原因:’无效参数不满足:date” 我已经经历了几个小时的代码,找不到问题.这可能是因为我没有检查为零,没有日期,第一次应用程序安装和启动,这可能是导致崩溃.如果是,我该如何检查这个代码中的零?我在编程方面还很新,任 在执行日期选择器之后,我在 Xcode中遇到一个非常令人沮丧的错误.调试器中的错误是:“由于未捕获异常终止应用程序”NSInternalinconsistencyException“,原因:’无效参数不满足:date”

我已经经历了几个小时的代码,找不到问题.这可能是因为我没有检查为零,没有日期,第一次应用程序安装和启动,这可能是导致崩溃.如果是,我该如何检查这个代码中的零?我在编程方面还很新,任何帮助都将不胜感激.这是代码:

#import "DatePickerVIEwController.h"@implementation DatePickerVIEwController@synthesize datePicker;- (ID)initWithNibname:(Nsstring *)nibnameOrNil bundle:(NSBundle *)nibBundleOrNil {    if (self = [super initWithNibname:nibnameOrNil bundle:nibBundleOrNil]) {    // Initialization code    }    return self;}- (BOol)shouldautorotatetoInterfaceOrIEntation:(UIInterfaceOrIEntation)interfaceOrIEntation {    // Return YES for supported orIEntations    return (interfaceOrIEntation == UIInterfaceOrIEntationPortrait);}- (voID)dIDReceiveMemoryWarning {    [super dIDReceiveMemoryWarning]; // Releases the vIEw if it doesn't have a supervIEw    // Release anything that's not essential,such as cached data}- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    UIlocalnotification *localNotif = [[UIlocalnotification alloc] init];    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];    [dateFormatter setDateFormat:@"mm'/'dd'/'yyyy"];    NSDate *eventDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"DatePickerVIEwController.selectedDate"];    localNotif.fireDate = [eventDate dateByAddingTimeInterval:-13*60*60];    localNotif.timeZone = [NSTimeZone defaultTimeZone];    localNotif.alertbody = @"Tomorrow!";    localNotif.alertAction = nil;    localNotif.soundname = UIlocalnotificationDefaultSoundname;    localNotif.applicationIconBadgeNumber = 0;    [[UIApplication sharedApplication]presentlocalnotificationNow:localNotif];        return YES;}- (voID)vIEwDIDLoad {    NSDate *storedDate = [[NSUserDefaults standardUserDefaults]                   objectForKey:@"DatePickerVIEwController.selectedDate"];    [self.datePicker setDate:storedDate animated:NO];}- (IBAction)dateChanged:(ID)sender {    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];    NSDate *selectedDate = [self.datePicker date];    [defaults setobject:selectedDate forKey:@"DatePickerVIEwController.selectedDate"];}
解决方法 在使用它之前,您不检查日期是否为null.

(voID)vIEwDIDLoad {    NSDate *storedDate = [[NSUserDefaults standardUserDefaults]                       objectForKey:@"DatePickerVIEwController.selectedDate"];    // add this check and set    if (storedDate == nil) {        storedDate = [NSDate date];    }    // ---    [self.datePicker setDate:storedDate animated:NO];}
总结

以上是内存溢出为你收集整理的ios – Xcode:参数无效全部内容,希望文章能够帮你解决ios – Xcode:参数无效所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1063968.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存