2016-07-15 57 views
-1

我在視圖中有5個dropdownlist。我想打開並關閉drodownlist(UIView),如下所示:
1.如果我點擊第一個按鈕,它將打開下拉列表,第二次點擊它將關閉。
2.如果一個下拉列表在第一個按鈕點擊打開,我點擊第二個按鈕,則第一個下拉列表將關閉,第二個下拉列表將打開。
我可以打開和關閉下拉列表(1)。但在第二種情況下,我不能。
這是我的代碼。uiviewcontroller中的多DropDownList

if ([self.DropDownView isDescendantOfView:self.view]) 
{ 


     [self dropDownCloseAnimation:sender withTF:nil]; 
     [self.DropDownView removeFromSuperview]; 
//  [self performSelector:@selector(showMenu:) withObject:sender afterDelay:0.1]; 
    } 
    else 
    { 
     [self.SinupView addSubview:self.DropDownView]; 
     [self dropDownAnimation:sender withTF:nil]; 
    } 


這裏是生命的下拉列表的功能

-(void)dropDownCloseAnimation : (UIButton *)sender withTF : (UITextField *)textField 
{ 
    if (sender.tag == 203 || textField.tag == 106) 
    { 
     [UIView animateWithDuration:0.9 animations:^{ 
      self.DropDownView.frame = CGRectMake(self.TFVehicalType.frame.origin.x, self.TFVehicalType.frame.origin.y + self.TFVehicalType.frame.size.height + 2, self.TFVehicalType.frame.size.width, 0); 
     } completion:nil]; 
    } 
    else if (sender.tag == 204 || textField.tag == 107) 
    { 
     [UIView animateWithDuration:0.5 animations:^{ 
      self.DropDownView.frame = CGRectMake(self.TFVehicalColor.frame.origin.x, self.TFVehicalColor.frame.origin.y + self.TFVehicalColor.frame.size.height + 2, self.TFVehicalColor.frame.size.width, 0); 
     } completion:nil]; 
    } 
    else if (sender.tag == 205 || textField.tag == 112) 
    { 
     [UIView animateWithDuration:0.5 animations:^{ 
      self.DropDownView.frame = CGRectMake(self.TFCity.frame.origin.x, self.TFCity.frame.origin.y + self.TFCity.frame.size.height + 2, self.TFCity.frame.size.width, 0); 
     } completion:nil]; 
    } 
    else if (sender.tag == 206 || textField.tag == 113) 
    { 
     [UIView animateWithDuration:0.5 animations:^{ 
      self.DropDownView.frame = CGRectMake(self.TFLocation.frame.origin.x, self.TFLocation.frame.origin.y + self.TFLocation.frame.size.height + 2, self.TFLocation.frame.size.width, 0); 
     } completion:nil]; 
    } 
    else if (sender.tag == 207 || textField.tag == 114) 
    { 
     [UIView animateWithDuration:0.5 animations:^{ 
      self.DropDownView.frame = CGRectMake(self.TFStatus.frame.origin.x, self.TFStatus.frame.origin.y + self.TFStatus.frame.size.height + 2, self.TFStatus.frame.size.width, 0); 
     } completion:nil]; 
    } 
} 
+0

如果我理解正確的,你有5個下拉菜單,如果你點擊一個和其他一些一個是開放的,你要關閉它? –

+0

是的。這是正確的。和我只有一個視圖打開沒有不同的所有 –

回答

0

1-製造陣列

2-每個下拉添加到數組您在操作屏幕

-3-上顯示它時按下以打開/關閉任何後下拉菜單,讓我們只是做了

4-陣列上的循環,關閉各個下拉在每次迭代

5打開寄件人之一。

快樂編碼!

+0

任何想法,然後循環? –

+0

把每一個放在.h中,然後調用並關閉它們。這對你有幫助嗎? –

+0

我只有一個視圖,而不是每個視圖的不同視圖。我只是在視圖控制器中使用關於其按鈕框架的動畫添加該視圖。看到我的問題。它具有密切的動畫代碼..同時我爲開放視圖編碼。 –

0

你應該用你的邏輯,給出如下,

-(void)btn1Click{ 
    Dropdown1Show=Yes; 
    DropDown2Show=NO; 
    DropDown3Show =NO; 
    DropDown4Show=NO; 
    } 
    -(void)btn2Click{ 
    Dropdown1Show=NO; 
    DropDown2Show=YES; 
    DropDown3Show =NO; 
    DropDown4Show=NO; 
    } 
    -(void)btn3Click{ 
    Dropdown1Show=NO; 
    DropDown2Show=NO; 
    DropDown3Show =YES; 
    DropDown4Show=NO; 
    } 
    -(void)btn4Click{ 
    Dropdown1Show=NO; 
    DropDown2Show=NO; 
    DropDown3Show =NO; 
    DropDown4Show=YES; 
    } 
+0

我只有一個視圖的所有5按鈕打開下拉列表 –

+0

@ios開發人員但是,你已經創建了五個對象的五個下拉菜單嗎?如果是,那麼我在哪裏寫了是否已經創建並且沒有設置爲零? –

+0

@ios開發人員希望你從中得到一個主意。如果你的問題解決了,那麼請標記答案正確 –

0

有不同的方法來做到這一點就像你可以使用一個下拉列表以及所有按鈕以及數據源的按鈕更改框架。您可以使用標籤屬性來區分按鈕和下拉列表。通過這種方式,您可以重用您的代碼並輕鬆處理數據流。

感謝

+0

。但我一次只想打開一個下拉菜單。我想不出來。 –

+0

由於沒有其他對象,它一次只能顯示一個下拉菜單。你必須在你的代碼中處理這個。 – surendrasheoran

+0

可以請更新您的想法與代碼 –

0

嘗試這個

This Drop down will help You. 
https://github.com/BijeshNair/NIDropDown 
+0

這是一個很好的控制器,但它的工作只有一個下拉菜單,而不是多個..因爲我的要求 –

+0

創建多少個按鈕你有很多對象,例如:-NIDropDown * dropDown,* dropDown2;所以它會打開所有下拉菜單。 – Rameshios