如何为iPhone应用程序制作下拉列表

时间:2012-07-04 06:27:33

标签: iphone xcode

我想为iphone应用程序制作一个下拉列表我希望当用户点击它显示列表时,点击任何按钮时它会显示我使用下面的代码实现的值和隐藏列表但这只适用于一个值不适合他人

  @interface DropDownViewController : UIViewController {

IBOutlet UILabel*ddText;
IBOutlet UILabel*ddMenu;
IBOutlet UIButton*ddMenuShowButton;


  }

 @property (nonatomic, retain) IBOutlet UILabel *ddText;
 @property (nonatomic, retain) IBOutlet UIView *ddMenu;
 @property (nonatomic,retain) IBOutlet UIButton *ddMenuShowButton;
 - (IBAction)ddMenuShow:(UIButton *)sender;
 - (IBAction)ddMenuSelectionMade:(UIButton *)sender;
 @end



 @implementation DropDownViewController
 @synthesize ddMenu, ddText;
 @synthesize ddMenuShowButton;

 - (IBAction)ddMenuShow:(UIButton *)sender
 {
    self.ddMenu.hidden = NO;
    [sender setTitle:@"▲" forState:UIControlStateNormal];


 }

 - (IBAction)ddMenuSelectionMade:(UIButton *)sender
{

 self.ddText.text = sender.titleLabel.text;
[self.ddMenuShowButton setTitle:@"▼" forState:UIControlStateNormal];


self.ddMenu.hidden = YES;

  }

我有三个按钮红色grenn蓝色首先是红色它只适用于红色而不适用于其他人如何解决这个问题我已经使用过本教程后面的这个

http://www.edumobile.org/iphone/iphone-programming-tutorials/a-simple-drop-down-list-for-iphone/

2 个答案:

答案 0 :(得分:0)

在文本域附近添加UI按钮。单击该按钮时,根据textfileld大小创建UITableview。(希望你知道创建Uitableview)然后在“cellForRowIndex”中加载listview内容。选择表格的行时,你可以从“didselectrowatIndexPath”中获取值并将其加载到textfield中。之后删除UItableview。

答案 1 :(得分:-2)

如果您在应用程序中使用iPhone工具会很好。您应该在下拉列表中使用UIPickerView。它看起来不错,并在移动应用程序中提供更好的界面