obj-c : iphone编程pickerview titleforrow方法问题
我有一个包含 2 个组件的 pickerView,当我选择组件 1 中的第 1 行时,它会将一个数组列表加载到组件 2 中。如果我选择组件 1 中的第 2 行,它将加载另一个数组列表组件2.有可能吗?
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component == 0){
return [arraylist1 count];
if (component == 1) {
if ([pickerViewcustom selectedRowInComponent:0] == 0) {
return [arraylist3 count];
}
}
}
return 0;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == 0){
return [arraylist1 objectAtIndex:row];
if (component == 1) {
if ([pickerViewcustom selectedRowInComponent:0] == 0) {
return [arraylist3 objectAtIndex:row];
}
}
}
return 0;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
return 150;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
[pickerViewcustom reloadComponent:0];
[pickerViewcustom reloadComponent:1];
}
i got a pickerView with 2 components, when i select for exemple the row 1 in the component 1 it will load an array list into the component 2. and if i select the row 2 in the component 1 it will load another array list in the component 2. It is possible?
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component == 0){
return [arraylist1 count];
if (component == 1) {
if ([pickerViewcustom selectedRowInComponent:0] == 0) {
return [arraylist3 count];
}
}
}
return 0;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == 0){
return [arraylist1 objectAtIndex:row];
if (component == 1) {
if ([pickerViewcustom selectedRowInComponent:0] == 0) {
return [arraylist3 objectAtIndex:row];
}
}
}
return 0;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
return 150;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
[pickerViewcustom reloadComponent:0];
[pickerViewcustom reloadComponent:1];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的事情:
在这个例子中使用了 NSDictionary,但你也可以只使用数组。
不客气,
阿里尔多
Try something like this:
In this example a NSDictionary was used, but you can use just arrays too.
You're welcome
Arildo