UIPickerView가있는 뷰에 있습니다. 여기에 내 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];
}
나는이 두 가지 방법의 NSLog([sortedArray componentsJoinedByString:@", "]);
을 할 수 있으며 는 작동합니다
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
및
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
하지만이 방법 같은 추적을 할 그것을 아무튼를 (작동하지 않음) :
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
sortedArray가 모든 곳에서 작동하지만이 방법에서는 왜 작동하는지 이해할 수 없습니다. sortedArrayUsingSelector:
의 문서에서
어디 정렬 된 배열이 정의 ... 메모리 누수 -
은 BTW, 난 당신이
studentNames
를 공개하지 않는 것을 볼? –sortedArray가 헤더에 정의됩니다. – tazboy
시도해 보셨습니까 [self setSortedArray : [studentNames sortedArrayUsingSelector : @selector (caseInsensitiveCompare :)]]; –