views:

23

answers:

1

I'm in a view that has a UIPickerView. Here is where I'm making my sortedArray.

- (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];
}

I can do an NSLog([sortedArray componentsJoinedByString:@", "]); in these two methods and it works:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

and

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component

but when I do that same trace in this method it doesn't work (It crashes):

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

I don't understand why the sortedArray works everywhere but in this one method.

A: 

From documentation of sortedArrayUsingSelector::

The new array contains references to the receiver’s elements, not copies of them.

Maybe the original strings are already released?

BTW, I see that you don't release the studentNames - memory leak...

Michael Kessler