0

我是 Xcode 的新手。

我正在尝试制作我的第二个 iPhone 应用程序,它基于酒精饮料,如何准备它们(例如:Sex on the beach、Daikiri 等)

我的问题是如何更改选择器选项并在每个选项中存储信息。

当用户从选择器中选择特定饮料时,加载信息..

我怎样才能做到这一点 ?

4

1 回答 1

1

You can use UIPickerView controller to perform this task.

Take UIPickerView controller in the xib of viewcontrller in which you want to do this task.

Then specify UIPickerViewDelegate,UIPickerViewDataSource and IBOutlet UIPickerView *pickerview in your viewcontroller.h file.

Then use delegate methods of UIPickerView as follows ;

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
    return 1; 
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
    return [yourArray count]; //give array that contains the alcoholic drinks values....
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
    return [yourArray objectAtIndex:row]; //display alcoholic drinks in picker....

}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
  //display whichever information you want to display after selection in picker
}
于 2013-07-24T10:14:33.700 回答