我的应用程序在iOS 5.x上构建和运行完美,但是在iOS 6中调用UIPickerView
的selectRow:inComponent:animated:
方法时会崩溃。
代码:
[_pickerview selectRow:1 inComponent:0 animated:NO];
我在搜索时得知这种方法在iOS6上不起作用,但我想知道其他实现此效果的方法。
我的应用程序在iOS 5.x上构建和运行完美,但是在iOS 6中调用UIPickerView
的selectRow:inComponent:animated:
方法时会崩溃。
代码:
[_pickerview selectRow:1 inComponent:0 animated:NO];
我在搜索时得知这种方法在iOS6上不起作用,但我想知道其他实现此效果的方法。
pickerView.selectRow(xxx, inComponent: yyy, animated: false)
amPmArray = [[NSMutableArray alloc] initWithObjects:@"AM",@"PM", nil];
我在选择器中设置了值:[picker selectRow:[amPmArray indexOfObject:currentTimeAMPMString] inComponent:5 animated:NO];
我始终得到小写字母的currentTimeAMPMString值,例如'am, pm',而我的数组不包含这种类型的项目,所以我会遇到崩溃错误。经过三天的查找,我发现如果您正在使用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];
selectRow:inComponent:animated:
在 iOS 6 中是有效的。 - sunkehappy-1
,但该处应该是范围为{0, 1}内的数字。但是根据你所粘贴的代码,实际上你确实使用了1
,因此你需要再粘贴更多真实的代码。 - sunkehappyi
或[arr objectAtIndex:i]
会给你一个-1
。 - sunkehappy