我有一个pickerView,它出现在模拟器中,但只要我尝试并滚动它,就会在main.m文件中崩溃EXC_BAD_ACCESS。PickerView在移动时崩溃EXC_BAD_ACCESS
我知道这是与我从pList加载的数组有关的,因为当我在程序中初始化的数组尝试这个数组时,它是如何处理的'无'在阵列的末尾?如果是这样,我怎么能看到这个,我怎么能添加它。
我感谢有这方面的帮助,请我拉着还剩下些什么我的头发,我是相当新的这个...
// 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];
}
非常感谢Thankyou,我很感谢你在回答时间和它的工作。它恰好是我读这篇文章http://stackoverflow.com/questions/2426651/pickerview-exc-bad-access - 这是同样的问题。我在界面中声明了这些变量,但我想这并不能使它们成为全局变量。 – John67
@ John67欢迎您:) – albertamg