Objective c 程序接收信号“;SIGABRT“;

Objective c 程序接收信号“;SIGABRT“;,objective-c,ios4,Objective C,Ios4,嘿,伙计们,我正在制作一个iphone应用程序,它使用uipicker从用户那里获取输入。我有四个不同的UIPicker和独立的数组。4个阵列中有2个可以工作。我可以从中选择值。然而,当点击另外两个元素时,其中一个会显示“SIGABRT”消息,而另一个元素在到达第8个元素时也会显示同样的消息。这是我的代码 - (void)viewDidLoad{ subtypepickerarray =[[NSMutableArray alloc]init]; [subtypepicke

嘿,伙计们,我正在制作一个iphone应用程序,它使用uipicker从用户那里获取输入。我有四个不同的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];

    }
}
在检查输出后,我发现了这个

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

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

数组包含的对象少于您尝试访问的对象

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

因此,请检查数组的计数并相应地填充选择器

还要检查您的所有4个阵列是否正确填写了数据


希望这能有所帮助。

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

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { NSUInteger numRows; numRows = (NSUInteger)[yourArray count]; } -(NSInteger)pickerView:(UIPickerView*)pickerView行数组件:(NSInteger)组件 { 整数numRows; numRows=(NSUInteger)[yourray count]; } 谢谢大家!:)我忘了在-'(NSInteger)pickerView:(UIPickerView*)pickerView numberOfRowsInComponent:(NSInteger)component'中添加一个返回,这就是问题的原因 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { NSUInteger numRows; numRows = (NSUInteger)[yourArray count]; }