开发者

Array disappears

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)numberOfCom开发者_StackOverflowponentsInPickerView:(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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜