UIPickerController에서 작업 중입니다. 모든 것이 작동하지만 이전 버튼을 눌러 이전보기로 이동하면 앱이 다운됩니다.내 응용 프로그램 충돌의 원인을 찾을 수 없습니다.
메모리 누수가 발생할 수 있다고 생각합니다.
여기 내 코드입니다. 누군가 내가 본 것을 놓친 경우 또는 원인에 대한 단서가있을 수 있습니다. 디버거에 아무 것도 표시되지 않습니다. 두 [pickerView 해제]를 가지고있는 할당 해제에
;
@synthesize colorTextField, pickerView, pickerToolbar;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[colorTextField release];
[pickerView release];
[pickerToolbar release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidLoad
{
[super viewDidLoad];
colorsArray = [[NSMutableArray alloc] init];
[colorsArray addObject:@"Red"];
[colorsArray addObject:@"Orange"];
[colorsArray addObject:@"Yellow"];
[colorsArray addObject:@"Green"];
[colorsArray addObject:@"Blue"];
[colorsArray addObject:@"Indigo"];
[colorsArray addObject:@"Violet"];
}
- (void)setColor
{
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
[pickerView release];
pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, actionSheet.bounds.size.width, 44)];
[pickerToolbar setBarStyle:UIBarStyleBlack];
[pickerToolbar sizeToFit];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(pickerDoneClicked)];
[pickerToolbar setItems:[NSArray arrayWithObject:doneButton] animated:NO];
[doneButton release];
[actionSheet addSubview:pickerToolbar];
[pickerToolbar release];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
- (void)pickerDoneClicked
{
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
[actionSheet release];
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[self setColor];
return NO;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [colorsArray count];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [colorsArray objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(@"Selected Color: %@. Index of selected color: %i", [colorsArray objectAtIndex:row], row);
[colorTextField setText:(NSString *)[colorsArray objectAtIndex:row]];
}
- (void)viewDidUnload
{
[self setColorTextField:nil];
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
게시하는 코드를 약간만 선택하면 다른 사용자에게 도움이됩니다. 예를 들어, initWithNibName : bundle : 및 didReceiveMemoryWarning 코드는 템플릿 코드 일뿐입니다. 게시 할 필요가 없습니다. shouldAutoroateToInterfaceOrientation : 메서드를 질문의 성격에 포함시킬 필요가 없다고 확신 할 수 있습니다. – Obliquely