ios - -[UIPickerTableView _createPreparedCellForGlobalRow :withIndexPath:],/SourceCache/UIKit_Sim/UIKit-2903.2/UITableView.m:7768 断言失败

标签 ios uitableview uiview uipickerview

我试图用 UIToolBar 显示 UIPickerView 但出现了一些错误。

这是我的代码 -

CGRect toolbarTargetFrame = CGRectMake(0, self.view.bounds.size.height-216-44, 320, 44);
CGRect datePickerTargetFrame = CGRectMake(0, self.view.bounds.size.height-216, 320, 216);

UIView *darkView = [[UIView alloc] initWithFrame:self.view.bounds];
darkView.alpha = 0;
darkView.backgroundColor = [UIColor blackColor];
darkView.tag = 9;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissDatePicker:)];
[darkView addGestureRecognizer:tapGesture];
[self.view addSubview:darkView];

UIDatePicker *picker = [[UIDatePicker alloc] init];
picker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
picker.datePickerMode = UIDatePickerModeDate;
[picker addTarget:self action:@selector(dueDateChanged:) forControlEvents:UIControlEventValueChanged];
[picker setFrame:CGRectMake(0,235,320,120)];
picker.backgroundColor = [UIColor blackColor];
[self.view addSubview:picker];

UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
toolBar.tag = 11;
toolBar.barStyle = UIBarStyleBlackTranslucent;

UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] ;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissDatePicker:)];

[toolBar setItems:@[spacer, doneButton]];
[self.view addSubview:toolBar];

[UIView beginAnimations:@"MoveIn" context:nil];
toolBar.frame = toolbarTargetFrame;
picker.frame = datePickerTargetFrame;
darkView.alpha = 0.5;
[UIView commitAnimations];

在这一行出现错误 -

picker.frame = datePickerTargetFrame;

这是错误 -

*** Assertion failure in -[UIPickerTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-2903.2/UITableView.m:7768
2013-10-03 13:43:12.688 Mistoh Beta 1[7228:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource is not set'

libc++abi.dylib: terminating with uncaught exception of type NSException

请帮助我。提前谢谢你。

最佳答案

我也遇到了同样的问题,是iOS7.03开始出现的crash。 可以通过移动来解决 [self.view addSubview:picker]; 在例程结束时,基本上是在设置选择器的框架之后。 IE。 picker.frame = datePickerTargetFrame;

[self.view addSubview:picker]; 必须在所有选择器操作之后添加

关于ios - -[UIPickerTableView _createPreparedCellForGlobalRow :withIndexPath:],/SourceCache/UIKit_Sim/UIKit-2903.2/UITableView.m:7768 断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19155082/

相关文章:

ios - Tableview重新加载数据将数字恢复为默认值

ios - 如何使 autosize(height) UITableViewCell?

ios - 如何在 UITableView 中显示 2 个自定义单元格

iphone - UIView背景图片透明度问题

swift - 如何正确匹配自定义 View 的框架与 TableViewCell 框架?

ios - 在 Parse 中存储 GPS 位置数据

ios - LoadVIew() 中的 UIVisualEffectView

ios - 在 iPhone 上使用 opencv 跟踪对象大小

ios - 如何确定 UITableView 性能低下的原因

ios - UIView bounds.applying 但旋转