Iphone 具有不同值的两个PickerView
这是我为一个视图控制器中的两个pickerviews编写的代码。然而,这对我不起作用Iphone 具有不同值的两个PickerView,iphone,ios,cocoa-touch,ios4,Iphone,Ios,Cocoa Touch,Ios4,这是我为一个视图控制器中的两个pickerviews编写的代码。然而,这对我不起作用 #pragma mark UIPickerViewDelegate methods //PickerViewController.m - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { return 1; } - (NSInteger)pickerView:(UI
#pragma mark UIPickerViewDelegate methods
//PickerViewController.m
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
switch ([thePickerView tag]) {
case 1: //purpose picker
return [m_arrPurpose count];
case 2: //second picker
return [m_arrSweep count];
default:
return 0;
break;
}
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
switch ([thePickerView tag]) {
case 1: //purpose picker
{
//cost.text = @"Test";
Purpose *prp = [m_arrPurpose objectAtIndex:row];
return [prp m_purposeName];
}
case 2: //second picker
{
OpenActivity *opn = [m_arrSweep objectAtIndex:row];
return [opn m_ahhaName];
}
default:
return @"";
break;
}
}
有人能帮我吗。。
谢谢听起来您的标记设置不正确,或者您没有连接两个选择器的数据源和委托方法 在numberOfRowsInComponent和titleForRow:methods中添加一些NSLog语句 在日志中包括选择器视图对象和选择器视图的标记,例如
NSLog(@"Rows in component for %@, tag %d",thePickerView,[thePickerView tag]);
标题下还有一段不同的文字
您应该看到两个不同的对象—如果没有,则表示委托和数据源未连接。你应该看到标签1和2-如果没有,你的标签设置不正确 对于这个问题,我的代码没有什么问题,只是我忘了在XIB中将标记的值设置为1和2 有什么问题吗?关于错误、崩溃、日志呢?你有什么问题?你在控制台上收到了什么错误?要添加到现有的评论中,你需要告诉我们什么不起作用。你是否得到了错误的值,没有值,崩溃,什么?就目前而言,这是无法回答的。Purpose和openActivity类中包含了什么?您是否将选择器的标记分别设置为1和2?那么,我回答的第一句话是什么?谢谢你。