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

标签 iphone view crash controller picker

我是 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/

相关文章:

java - LibGDX 游戏崩溃并显示 "java platform se binary stopped working"

iphone - 使用 setViewControllers 时 UINavigationController 导致应用程序崩溃

Android GPS 检查崩溃?

iphone - 在启动前添加屏幕

iphone - 将屏幕从 Mac 流式传输到 iPhone

Android 在此图片之上绘制图片(动态)

django - 使用 Django 通用 View 时,我可以过滤 request.user 吗?

ios - 图像 Assets 在 iOS 中无法正常工作 [大问题]

iphone - 在 iOS 6 UIWebview 组件中显示智能横幅

ios - Xcode iOS 知名度 "zoom box"