Iphone 阵列消失

Iphone 阵列消失,iphone,uipickerview,Iphone,Uipickerview,我在一个有UIPickerView的视图中。这是我做分类的地方,Darray - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSMutableArray *studentNames = [[NSMutableArray alloc] init]; for (Student *student in course.students) [studentNames add

我在一个有UIPickerView的视图中。这是我做分类的地方,Darray

- (void)viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];

   NSMutableArray *studentNames = [[NSMutableArray alloc] init];

   for (Student *student in course.students)
      [studentNames addObject:student.name];

   sortedArray = [studentNames sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

   [picker selectRow:(kRowMultiplier*sortedArray.count)/2 inComponent:0 animated:NO];
}
我可以做一个NSLog[sortedArray Components sJoinedByString:@,];在这两种方法中,它是有效的:

但当我用这种方法进行同样的跟踪时,它不起作用,它崩溃了:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
我不明白为什么SorterDarray在任何地方都能工作,但只能使用这一种方法。

来自SorterDarray的文档UsingSelector::

新数组包含对接收器元素的引用,而不是它们的副本

也许原始字符串已经被释放了


顺便说一句,我看到您没有释放studentNames-内存泄漏…

排序数组在哪里定义?排序数组在标头中定义。您是否尝试过[self-setSortedArray:[studentNames sortedArray UsingSelector:@selectorcaseInsensitiveCompare:];我甚至不认为这是一个排序数组问题了。我相信这个问题源于没有正确保存学生对象。我不确定我把事情搞砸了,但因为你是唯一一个给出答案的人,所以我会给你评分。因为你注意到了我的漏洞。谢谢
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component