gpt4 book ai didi

iphone - 滚动超过列表的开头或结尾时,UIPickerView 使应用程序崩溃

转载 作者:行者123 更新时间:2023-12-03 15:57:15 25 4
gpt4 key购买 nike

我是 iOS 开发新手,所以这可能很容易解决。我有一个自定义 View Controller ,我在其中采用协议(protocol)来控制 Nib 中的 UIPickerView。一切正常,除非在 iPad 模拟器中,我将选择器滚动到列表中的第一项或列表中的最后一项之外并释放。它踢出以下错误:

线程1:程序接收信号:“EXC_BAD_ACCESS”

在我的 main.m 类的这一行:

int retVal = UIApplicationMain(argc, argv, nil, nil);

相关代码如下:

View Controller .h

@interface BirdColorViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
IBOutlet UIPickerView *birdColorPicker;
NSArray *birdColors;
}

@property (nonatomic,retain) IBOutlet UIPickerView *birdColorPicker;

View Controller .m
- (void)dealloc
{
[birdColorPicker release];
[super dealloc];
}

...
- (void)viewDidLoad
{
[super viewDidLoad];
birdColors = [NSArray arrayWithObjects:@"Blue",@"Yellow",@"Red",nil];

birdColorPicker.delegate = self;
birdColorPicker.dataSource = self;
}

...

#pragma mark - UIPickerViewDataSource methods

//(UIPickerView *)thePickerView

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [birdColors count];
}

#pragma mark - UIPickerViewDelegate methods

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [birdColors objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// Set value in prefs/model
}

最佳答案

尝试:birdColors = [[NSArray alloc] initWithObjects:@"Blue",@"Yellow",@"Red",nil];而不是 birdColors = [NSArray arrayWithObjects:@"Blue",@"Yellow",@"Red",nil];

关于iphone - 滚动超过列表的开头或结尾时,UIPickerView 使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5491742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com