iOS 6中UIPickerView选择行崩溃问题

3

我的应用程序在iOS 5.x上构建和运行完美,但是在iOS 6中调用UIPickerViewselectRow:inComponent:animated:方法时会崩溃。

代码:

[_pickerview selectRow:1 inComponent:0 animated:NO];

我在搜索时得知这种方法在iOS6上不起作用,但我想知道其他实现此效果的方法。


你能贴上你的崩溃日志吗?而且 selectRow:inComponent:animated: 在 iOS 6 中是有效的。 - sunkehappy
你能检查一下第一行是否真的存在吗?通常崩溃是由于不存在的行或组件引起的。 - John
你的崩溃日志显示你在代码中使用了-1,但该处应该是范围为{0, 1}内的数字。但是根据你所粘贴的代码,实际上你确实使用了1,因此你需要再粘贴更多真实的代码。 - sunkehappy
@sunkehappy [_pickerview selectRow:[arr objectAtIndex:i] inComponent:0 animated:NO]; - Gener Kill
请提供更多的代码(更新您的问题,不要通过添加评论来添加代码)。我猜你的i[arr objectAtIndex:i]会给你一个-1 - sunkehappy
显示剩余3条评论
3个回答

9
你的崩溃日志显示你在代码中使用了-1,而这里应该是在{0,1}范围内的数字。但在你粘贴的代码中,确实使用了1。因此,你需要检查你的xxx和yyy参数。
pickerView.selectRow(xxx, inComponent: yyy, animated: false)

1
上述答案是正确的,但如果数组的值与选择器的值不同,则会出现此错误。
这是我的代码 我是这样初始化的: amPmArray = [[NSMutableArray alloc] initWithObjects:@"AM",@"PM", nil]; 我在选择器中设置了值:[picker selectRow:[amPmArray indexOfObject:currentTimeAMPMString] inComponent:5 animated:NO]; 我始终得到小写字母的currentTimeAMPMString值,例如'am, pm',而我的数组不包含这种类型的项目,所以我会遇到崩溃错误。

0

经过三天的查找,我发现如果您正在使用picker与textField相关联,请不要将任何文本分配给textField。 原因是当您使用以下文本时,它意味着已分配的测试应存在于数组中。

[self->pickerView selectRow:[self->dataArray indexOfObject:self->textField.text] inComponent:0 animated:NO];

使用这个。

[self->pickerView selectRow:[self->dataArray objectAtIndex:row] inComponent:0 animated:NO];


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接