简体   繁体   English

如何在Xcode选择器上存储信息?

[英]How to store information on an Xcode picker?

I'm new to Xcode. 我是Xcode的新手。

I'm trying to make my second iPhone application, it's based on alcoholic drinks , how to prepare them (for example: Sex on the beach, Daikiri, etc.) 我正在尝试制作第二个iPhone应用程序,该应用程序基于酒精饮料 ,制备方法(例如:在海滩上做爱,Daikiri等)

My question is how can I change the pickers options and store information in each one of them. 我的问题是如何更改选择器选项并将信息存储在每个选项中。

When the user chooses a specific drink from the picker load up the information.. 当用户从选择器中选择特定的饮料时,将加载信息。

How can i do this ? 我怎样才能做到这一点 ?

You can use UIPickerView controller to perform this task. 您可以使用UIPickerView控制器执行此任务。

Take UIPickerView controller in the xib of viewcontrller in which you want to do this task. 在要执行此任务的viewcontrller的xib中使用UIPickerView控制器。

Then specify UIPickerViewDelegate,UIPickerViewDataSource and IBOutlet UIPickerView *pickerview in your viewcontroller.h file. 然后在viewcontroller.h文件中指定UIPickerViewDelegate,UIPickerViewDataSourceIBOutlet UIPickerView *pickerview

Then use delegate methods of UIPickerView as follows ; 然后使用UIPickerView的委托方法,如下所示;

- (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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM