1

データが 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) でのアサーションの失敗

4

1 に答える 1

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 @"";
}
}
于 2013-04-22T02:59:29.977 に答える