【问题标题】:Program received signal "SIGABRT"节目接收信号“SIGABRT”
【发布时间】:2011-08-03 10:04:40
【问题描述】:

大家好,我正在制作一个使用 uipicker 获取用户输入的 iphone 应用程序。我有四个不同的 uipicker 和单独的数组。 4 个阵列中的 2 个有效。我可以从中选择值! .但是,其他两个在单击时会给我“SIGABRT”消息,而另一个在到达第 8 个元素时也会这样做!。这是我的代码!

- (void)viewDidLoad{
    subtypepickerarray =[[NSMutableArray alloc]init];
        [subtypepickerarray addObject:@"hello"];
        [subtypepickerarray addObject:@"object 2"];
        [subtypepickerarray addObject:@"jfhgsjdfhg"];
        [subtypepicker reloadAllComponents];

    lymphnodearray = [[NSMutableArray alloc]init];

    for (int j = 0; j<=10;j++){
        NSString *answer1 = [NSString stringWithFormat:@"%d",j];

        [lymphnodearray addObject:answer1];
        [Pos_lymppicker reloadAllComponents];

    }
}

当我收到错误消息时,它会突出显示这些代码

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
................
    else if (thePickerView == subtypepicker){

        return [subtypepickerarray objectAtIndex:row];

    }
    else {
        return[lymphnodearray objectAtIndex:row];
    }
}

检查输出后我发现了这个

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
*** Call stack at first throw:

这是否意味着我的数组是空的?我有点困惑!任何帮助,将不胜感激 !谢谢你

【问题讨论】:

    标签: objective-c ios4


    【解决方案1】:

    问题是您的 UIPickerView 数据源(在您的案例数组中)比 UIPicker 预期的要显示的项目更多。 您需要使用此方法才能使其正常工作

    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { NSUInteger numRows; numRows = (NSUInteger)[yourArray count]; }

    【讨论】:

    • 谢谢大家! :) 我忘了在 - '(NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component' 中添加一个返回值,这就是问题的原因
    【解决方案2】:

    数组包含的对象比您尝试访问的要少。

    它只有 3 个对象,而您正试图访问 4 个对象。

    所以请检查您的数组的数量并相应地填充选择器。

    还要检查您的所有 4 个数组是否都正确填写了您的数据。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多