我在具有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
但是當我做同樣的痕跡在這個方法中它沒有按't work(It crash):
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
我不明白爲什麼sortedArray無處不在,但在這一個方法。
哪裏定義數組排序? – 2010-07-14 21:42:27
sortedArray在標題中定義。 – tazboy 2010-07-14 22:32:09
你試過 [self setSortedArray:[studentNames sortedArrayUsingSelector:@selector(caseInsensitiveCompare :)]]; – 2010-07-15 01:13:46