【问题标题】:ios: UIPickerView lldb error when I try to scrollios:当我尝试滚动时 UIPickerView lldb 错误
【发布时间】:2013-04-22 02:34:41
【问题描述】:

我有一个视图需要等到从 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)

【问题讨论】:

  • 你也可以发布错误吗?
  • 我把上面的错误贴出来了

标签: ios uipickerview lldb


【解决方案1】:

将代码更改为:

- (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 @"";
}
}

【讨论】:

  • 这确实是一种解决方法。但是如果没有数据(空选择器),让选择器处于非活动状态会更好。
猜你喜欢
  • 1970-01-01
  • 2014-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-30
  • 2019-11-30
  • 1970-01-01
  • 2021-04-23
相关资源
最近更新 更多