我有一个视图需要等到从Web服务检索数据然后更新UI选择器视图。当我等待响应时,如果用户滚动选择器视图,应用程序崩溃,我得到lldb错误。有什么理由吗?
这是我的代码:
@interface LocavoreRetroSecondViewController ()
@end
@implementation LocavoreRetroSecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"I Ate Local", @"I Ate Local");
self.tabBarItem.image = [UIImage imageNamed:@"newfood"];
_dataController = [[InSeasonProductDataController alloc] init];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [_dataController countOfList];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
Product *product = [_dataController objectInListAtIndex:row];
return product.name;
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
//do something
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc{
[_dataController release];
[super dealloc];
}
我收到此错误:
* 断言失败 - [UITableViewRowData rectForRow:inSection:],/ SourceCache / UIKit_Sim / UIKit-2380.17 / UITableViewRowData.m:1630 (lldb)
答案 0 :(得分:2)
将代码更改为:
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if ([_dataController countOfList]>0) {
return [_dataController countOfList];
}else{
return 1;
}
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if ([_dataController countOfList]>0) {
Product *product = [_dataController objectInListAtIndex:row];
return product.name;
}else{
return @"";
}
}