2013-04-17 34 views
0

在iOS上,使用位於導航欄中的分段控件切換採集視圖的正確/最有效的方法是什麼?使用分段控件切換採集視圖

+0

你問如何添加一個分段控制到導航欄和對控制反應,或者你問如何切換集合視圖基於分段控制的動作? –

+0

如何切換集合視圖。 – nicktones

回答

3

你的意思是切換?其實你可以使用一個單一的集合視圖,並根據開關量

更改收集的數據源添加操作爲您分段控制,以更改數據源

- (IBAction)changeCollectionViewData:(UISegmentedControl*)sender { 

switch (sender.selectedSegmentIndex) { 
    case 0: 
     self.images =self.cars // displays images of cars; 
     break; 
    case 1: 
     self.images =self.bike // displays images of bikes; 
     break; 
} 
[self.collectionView reloadData] 

} 
// self.images is the data source array 

記住,你需要設置numberOfItemsInSection據此

+0

乾杯。可能會使用這種方法。 – nicktones