据我了解,我不应该保留作为委托或数据源的控制器。我制作了一个 UIPickerView,在属性访问器中创建,如下所示:
-(UIPickerView *)projectPicker {
if (_projectPicker != nil) {
return _projectPicker;
}
//Create Picker View
UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 185, 0, 0)];
picker.showsSelectionIndicator = YES;
//Create source and delegate
NSString *titleForRow0 = NSLocalizedString(@"<<Make Selection>>", @"projectPicker nil Label 0");
NSArray *titlesForFirstRows = [[NSArray alloc] initWithObjects:titleForRow0, nil];
ProjectPickerDatasource *pickerSource = [[ProjectPickerDatasource alloc] initWithManagedObjectContext:self.managedObjectContext
selectedProject:self.currentProject
andTitlesForFirstRows:titlesForFirstRows];
[titlesForFirstRows release];
picker.delegate = pickerSource;
picker.dataSource = pickerSource;
self.projectPicker = picker;
[pickerSource release];
[picker release];
return _projectPicker;
}
此崩溃报告尝试访问未分配的 pickerSource 实例。如果我将 pickerSource 组件拆分为另一个属性,从而将其保留在此控制器中,则它可以完美运行。我不认为这是正确的实施。pickerView 在销毁之前不会保留它的委托和数据源吗?