我在具有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