2010-10-08 47 views
5

我有一個視圖,我有一個按鈕,我需要有一個下拉框單擊該按鈕。如何實現下拉框? 下拉框shuold有一個表視圖。當我點擊表格視圖中的行(在下拉框打開後)我想獲取文本,這些文本將出現在我點擊按鈕的視圖上單擊的行單元格中。怎麼做?如何在iphone中實現下拉框?

+1

[在iphone下拉框]的可能重複(http://stackoverflow.com/questions/2643891/dropdown-box-in-iphone) – 2010-10-08 13:00:16

回答

0

有兩種方法可以做到只是在你的tableview中添加一個視圖,然後在其上放置一個tableview或show按鈕,這樣它就可以看到像下拉菜單,在任意單元格上選中的按鈕的錶行上調用該方法

+0

如何具有與所期望的尺寸的表格視圖點擊按鈕 – Vijay 2010-10-08 12:11:52

+0

uiview * DROPDOWNView = [[uiview alloc] initwithframe:cgrecktmake(100,100,200,100); uitableview * tableview [[uitableview alloc] intiwithframe:cgrectmake(0,0,200,100)]; [DROPDown addsubview:tableview]; – GhostRider 2010-10-08 12:25:32

+0

上面的解決方案不起作用 – Vijay 2010-10-11 07:48:49

2

有實現這個

  1. 使用的tableview兩種方式,你可以有你想要在你的下拉菜單中的項目列表中選擇一個的tableview。然後在UITableView的委託方法didselectrow中,您可以爲該特定行選中一個複選標記,然後在該項目的其他地方使用該特定行的值。

  2. 您可以使用Pickerview來實現下拉列表。

其中兩個PickerView是可取的。

3

這是一個適用於我的解決方法。

-(IBAction)showDropDownList:(id)sender 
{ 

tableView = [[UITableView alloc] initWithFrame:CGRectMake(7, 135, 200, 0) style:UITableViewStyleGrouped]; 
     tableView.delegate = self; 
     tableView.dataSource = self; 

    if (tableState == TableViewStateClosed) { //enum for identifying tableview state 

     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.3]; 
     CGRect viewRect = self.tableView.frame; 
     viewRect.size.height += 150; 

     [self.tableView setFrame:CGRectMake(7, 135, 200, viewRect.size.height)]; 

     [UIView commitAnimations]; 
     [self.view addSubview:tableView]; 
     tableState = TableViewStateOpen; 
    } 
    else if (tableState == TableViewStateOpen) { 

     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.3]; 

     [self.inboxTableView setFrame:CGRectMake(7, 135, 200, 0)]; 

     [UIView commitAnimations]; 

     tableState = TableViewStateClosed; 
    } 
} 
0

這是另一種選擇。如果您仔細考慮,操作表基本上是一個下拉列表。如果您不斷向UIActionSheet添加按鈕,它最終會變成一張桌子。所以只需要一個UIButton(或某個事件)觸發UIActionSheet。

嘗試向UIActionSheet添加7個或更多按鈕,並將它看成列表。它方便。

enter image description here