나는 pickerView가 있지만 시뮬레이터에 나타나지만 시도하고 스크롤하면 main.m 파일에서 EXC_BAD_ACCESS가 충돌합니다.이동했을 때 PickerView가 이동했을 때 EXC_BAD_ACCESS가 충돌 함
제가 pList에서로드하는 배열과 관련이 있다는 것을 알고 있습니다. 프로그램에서 초기화 된 배열로 이것을 시도하면 (주석 처리 된 섹션 참조), 'nil 배열 끝에? 그렇다면 어떻게 볼 수 있으며 어떻게 추가 할 수 있습니까? 나는 내 머리 밖으로의 왼쪽 무슨 당기는거야, 그리고 당신은 객체 (들)을 보유하고 있지 않습니다 ...
// Method to define the numberOfComponent in a picker view.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
// Method to define the numberOfRows in a component using the array.
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent :(NSInteger)component
{
if (component==0)
{
return [maximumSpeed count];
}
else
{
return[warningTime count];
}
}
//PickerViewController.m
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSString *stringToReturn = nil;
switch (component)
{
case 0:
stringToReturn = [maximumSpeed objectAtIndex:row];
break;
case 1:
stringToReturn = [warningTime objectAtIndex:row];
break;
}
return stringToReturn;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
// finding the path and loading the pList as a dictionary into 'data'
NSString *pListFile = [[NSBundle mainBundle] pathForResource:@"PropertyList" ofType:@"plist"];
data =[NSDictionary dictionaryWithContentsOfFile:pListFile];
// get and set up the 2 arrays
maximumSpeed = [data valueForKey:@"MaximumSpeed"];
warningTime = [data valueForKey:@"WarningTime"];
//maximumSpeed =[[NSArray alloc] initWithObjects:@"Running",@"Crying",@"Boring",@"Working",nil];
//warningTime = [[NSArray alloc] initWithObjects: @"Happy", @"Sad" , @"Good", @"joyce",nil];
NSLog(@"%@", maximumSpeed);
NSLog(@"%@", warningTime);
}
(void)viewDidUnload
{
[self setTxt1:nil];
[pickerView release];
pickerView = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[txt1 release];
[pickerView release];
[warningTime release];
[maximumSpeed release];
[super dealloc];
}
대단히 감사합니다. 답변에 시간을 내 주셔서 감사 드리며 효과가있었습니다. 그것은 단지 이렇게 나는이 게시물 http://stackoverflow.com/questions/2426651/pickerview-exc-bad-access-을 읽고 있었는데 - 이것은 같은 문제입니다. 인터페이스에서 이러한 변수를 선언했지만 전역 변수가 아니라고 생각합니다. – John67
@ John67 당신은 환영합니다 :) – albertamg