选择器没有加载数据

时间:2012-01-21 16:19:05

标签: iphone ios5

我有一个包含多个文本字段的详细视图,其中一个文本字段旁边有一个按钮,用户可以单击该按钮弹出单个组件选择器。隐藏选择器直到用户单击按钮。为了确保基础工作,我有一个简单的数组assignd到pickerdata。显示选择器工作的按钮但数据没有显示,这里是代码

- (IBAction)ButtonPressed 
{
    NSArray *array = [[NSArray alloc] initWithObjects:@"data", @"data 1", nil]; 
    self.pickerData = array;
    vPicker.hidden = NO;
    selectButton.hidden = NO;   
}


#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 
{ 
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{
    return [pickerData count]; 
}

#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView
             titleForRow:(NSInteger)row
            forComponent:(NSInteger)component 
{ 
    return [pickerData objectAtIndex:row];
}

1 个答案:

答案 0 :(得分:0)

在您的类的界面中包含UIPickerview数据源和委托。然后设置vpicker.datasource = self和vpicker.delegate = self;