我有以下代码块:
NSNumber* dayNsNumber = [[NSNumber alloc] initWithInt:dayNumber+1];
NSLog(@"dayNsNumber: %d", [dayNsNumber intValue]);
if(boolVar){
UIAlertView* success = [[UIAlertView alloc] initWithTitle:@"Title" message:[NSString stringWithFormat:@"Day %d!", dayNumber+1] delegate:self cancelButtonTitle:nil otherButtonTitles:@"Star", nil];
[success show];
NSLog(@"dayNsNumber: %d", [dayNsNumber intValue]);
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
dayNsNumber, "Day Number",
[self getCurrentLocalDate], @"Date",
[self getCurrentLocalTime], @"Time",
nil];
}
发生的情况是,当我运行代码时,它在初始化时挂起params
NSDictionary
并说dayNsNumber
是nil
.
Xcode 显示线程 1:EXC_BAD_ACCESS (code=1)。
我该如何解决这个问题?我想添加dayNsNumber
到我的params
字典中。
此外,还有getCurrentLocalDate
和getCurrentLocalTime
:
-(NSString*)getCurrentLocalDate;{
NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"dd-MM-yyyy" options:0 locale:[NSLocale currentLocale]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:formatString];
NSString *todayString = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"todayString: \"%@\"", todayString);
return todayString;
}
-(NSString*)getCurrentLocalTime;{
NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"HH:mm:ss zzz" options:0 locale:[NSLocale currentLocale]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:formatString];
NSString *timeString = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"timeString: \"%@\"", timeString);
return timeString;
}