2012-06-04 53 views
6

Tôi muốn danh sách thả xuống như listview khi tôi nhấp vào nút thả xuống và tạo danh sách có một số nội dung. sau đó bất kỳ nội dung tôi chọn nó sẽ là văn bản cho bất kỳ nhãn nào giúp tôi. Cảm ơn rất nhiều.Làm thế nào để tạo danh sách thả xuống mà không sử dụng UIPIckerviewcontroller trong IPhone?

+0

thể trùng lặp của [xem danh sách thả xuống trong iPhone] (http://stackoverflow.com/questions/3650525/dropdown-list-view-in-iphone) –

+0

Pleas làm theo các liên kết bạn sẽ được thực hiện mà bạn muốn tôi cũng đã thử những họ làm việc tốt http://iphone-rahulvarma.blogspot.com/2011/06/customized-drop-down-list-in-iphone.html http://ameyashetti.wordpress.com/2010/09/26/drop-down-demo/hy vọng điều này sẽ giúp – james

+0

Hãy xem [this] (https://github.com/vicpenap/VPPDropDown) kiểm soát. Nó là một trình đơn lựa chọn thả xuống cơ bản có thể được sử dụng để liệt kê các tùy chọn. – Bourne

Trả lời

1

Bạn có thể sử dụng pop-over để hiển thị danh sách. Trong cửa sổ pop-over bạn có thể tạo tableview để hiển thị danh sách các mục và khi người dùng chọn bất kỳ tùy chọn nào, didSelectRowAtIndexPath sẽ được gọi, từ phương pháp này bạn có thể gửi giá trị và hiển thị đã chọn trong nhãn.

Mã trong chế độ xem chính, nơi bạn muốn hiển thị trình đơn thả xuống.

if (m_OptionController !=nil) 
     { 
      [m_OptionController release]; m_OptionController = nil; 

     } 
     m_OptionController=[[OptionViewController alloc]init]; 
     [m_OptionController setTarget:self andSelector:@selector(displaySelectedOption:)]; 

     if(m_pPopOverController) 
     { 
      [m_pPopOverController dismissPopoverAnimated:YES]; 
      [m_pPopOverController release]; 
      m_pPopOverController=nil; 
     } 

     m_pPopOverController=[[UIPopoverController alloc]initWithContentViewController:m_OptionController]; 

     [m_pPopOverController setPopoverContentSize:CGSizeMake(thePopOverFrame.size.width, thePopOverFrame.size.height) animated:NO]; 
     [m_pPopOverController presentPopoverFromRect:CGRectMake(theButton.frame.origin.x,0,40,40) inView:self 
          permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

OptionViewController là UIViewController có chứa UITableView.Populate UITableView với dữ liệu (danh sách tùy chọn).

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if ([m_Target respondsToSelector:m_Selector]) { 
         [m_Target performSelector:m_Selector withObject:nil]; 
        } 
} 

Đừng quên để thiết lập mục tiêu bằng cách gọi phương pháp này, vì vậy khi người dùng chọn bất kỳ tùy chọn, phương pháp tương ứng trong mainviewcontroller được gọi là nơi bạn muốn giá trị được chọn.

- (void)setTarget:(id)inTarget andSelector:(SEL)inSelector 
{ 
    m_Target = inTarget; 
    m_Selector = inSelector; 
} 
+0

cảm ơn bạn rất nhiều –

Các vấn đề liên quan