2015-07-24 56 views

Trả lời

16

Có rất nhiều cocoacontrols để thực hiện chức năng này trong ứng dụng của bạn:

DropDown Menu Controls For iOS

Nhưng tôi nghĩ lmdropdownview là chính xác nhất.

Lỗi của tôi, btnavigationdropdownmenu ITS chính xác nhất cho những gì bạn đang yêu cầu (theo màn hình của bạn).

thực hiện (Swift) [Xem readme để được hướng dẫn speceific hơn, và tùy biến]:

let items = ["Most Popular", "Latest", "Trending", "Nearest", "Top Picks"] 

let menuView = BTNavigationDropdownMenu(frame: CGRectMake(0.0, 0.0, 300, 44), title: items.first!, items: items, containerView: self.view) 

self.navigationItem.titleView = menuView 

menuView.didSelectItemAtIndexHandler = {(indexPath: Int) ->() in 
      println("Did select item at index: \(indexPath)") 
      self.selectedCellLabel.text = items[indexPath] 
} 

Hy vọng nó giúp.

EDIT:

Cám ơn 'rsc' for the info, theres một objective-c version của cocoacontrol này:

#import "PFNavigationDropdownMenu.h" 


-(void)viewDidLoad{ 
    PFNavigationDropdownMenu *menuView = [[PFNavigationDropdownMenu alloc]initWithFrame:CGRectMake(0, 0, 300, 44)title:items.firstObjects items:items containerView:self.view]; 

    menuView.didSelectItemAtIndexHandler = ^(NSUInteger indexPath){ 
      NSLog(@"Did select item at index: %ld", indexPath); 
      self.selectedCellLabel.text = items[indexPath]; 
     }; 

     self.navigationItem.titleView = menuView; 

    } 
+0

Điều này có vẻ siêu, cảm ơn bạn! – TheBrownCoder

+1

https://github.com/qmathe/DropDownMenuKit –

+1

https://github.com/PerfectFreeze/PFNavigationDropdownMenu - Biến thể mục tiêu-C của BTNavigationDropdownMenu – rsc

4

thể workaround nếu bạn thích làm việc đó bằng tay:

Tạo hai UIButton (lên/xuống), chỉ định cái đầu tiên là navigationItem.titleView, thêm hành động cho UIControlEventTouchUpInside khi kiểm tra hành động này nếu các trạng thái thay đổi để mở rộng hoặc thu hẹp và phụ thuộc vào việc thêm/xóa UITableView wi th dataSource trống trên đầu trang UIViewControllerview, đặt khung thích hợp. Sau đó cập nhật nguồn dữ liệu và tải lại với hoạt ảnh hàng UITableViewRowAnimationBottom hoặc UITableViewRowAnimationTop phụ thuộc vào việc nó đang mở rộng hay thu gọn. Thay thế nút bằng nút thứ hai.

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