从 NSString 解析 NSDate 时出错
当我点击一行时,我的应用程序冻结,这是 didSelectRowAtIndexPath
的代码,stringDate
等于这样的字符串:Feb 4
。
EditView *editController = [[EditView alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:editController animated:YES];
NSDictionary *cellValue = [self.array objectAtIndex:[indexPath row]];
editController.savedString = [cellValue objectForKey:@"label"];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
NSString *stringDate = [cellValue valueForKey:@"date"];
NSDate *parsedDate = [df dateFromString:stringDate];
editController.savedDate = parsedDate;
[editController release];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
在 NSString *stringDate = [cellValue valueForKey:@"date"];
行点击行时出现此错误,并出现以下错误:
* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效参数不满足:日期”
更新: 解析的日期设置为 UIDatePicker 带有日期和;时间模式,我只是将字符串日期转换为
NSDate
以便与 [timePicker setDate:savedDateanimated:YES];
我创建了 cellValue
code> 作为一个 NSDictionary
,它基本上访问一个 plist
,我在其中创建了一个 NSDictionary
,然后用格式化的 NSString
编写它>。 array
显示 plist
数组,因此我可以使用 [cellValue objectForKey:@"date"]
访问它
NSDictionary *cellValue = [self.array objectAtIndex:[indexPath row]];
My app freezes when I tap a row, here is the code for didSelectRowAtIndexPath
, the stringDate
is equal to a string like this: Feb 4
.
EditView *editController = [[EditView alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:editController animated:YES];
NSDictionary *cellValue = [self.array objectAtIndex:[indexPath row]];
editController.savedString = [cellValue objectForKey:@"label"];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
NSString *stringDate = [cellValue valueForKey:@"date"];
NSDate *parsedDate = [df dateFromString:stringDate];
editController.savedDate = parsedDate;
[editController release];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
I get this error when tapping the row, on the line NSString *stringDate = [cellValue valueForKey:@"date"];
with this error:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: date'
UPDATE: The parsed date is set to a UIDatePicker
with date & time mode, and I am simply converting the string date to a NSDate
to be used with [timePicker setDate:savedDate animated:YES];
I created cellValue
as a NSDictionary
which basically accesses a plist
where I created a NSDictionary
and then wrote it with a formatted NSString
. And array
displays the plist
array, so I can access it using [cellValue objectForKey:@"date"]
NSDictionary *cellValue = [self.array objectAtIndex:[indexPath row]];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要告诉格式化程序您的字符串满足的格式
它应该是这样的:
You need to teach the formatter the format your string fulfills
It should be something like: