2013-04-27 57 views
-1

如何使用xcode4.5 storyboard在ios上的表中填充產品和類別的數組。我正在使用一個單一的視圖項目,你可以告訴我的步驟。 我發現了一些代碼,但他們使用.xib文件,我不知道如何在我的項目中添加一個.xib文件。它需要.xib文件還是可以在沒有.xib文件的情況下完成?Heirarchical子菜單 - ios?

例如:

icecreame

strawbwry 10 
    vanila  29 

蛋糕

strawbwry-cake 10 
    vanila -cake 29 
    pineApple -cake 29 
    pineApple -cake 29 

濾餅-2

strawbwry-cake 10 
    vanila -cake 29 
    pineApple -cake 29 
    pineApple -cake 29 

回答

0

使用分段式泰伯維使下拉表。

使用

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
    return 3; //Will return 3 sections (=categories) 
} 

每個類別和

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    if(section==0){ //Icecream 
     return 2; //You will have 2 products for ice cream 
    }else if(section==1){ 
     return 4; //You will have 4 products for cake. 
    } 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

做這樣的:

if(indexPath.section==0){ 
    //Icecream 
    //Create your cell and return it. 
}else if(indexPath.section==1){ 
    //Cake 
    //Again, create your instance of UITableViewCell and return it. 
} 
+0

我們如何才能在點擊時摺疊和擴大主層面? – zzzzz 2013-07-24 12:14:52

+0

我不確定你的意思。您是否在選擇其中一個單元格後對整個部分進行「摺疊」? – gasparuff 2013-07-24 12:22:27

+0

不,我正在談論摺疊或擴大部分已被點擊部分。例如,當我點擊冰淇淋,然後草莓和香草消失。當我再次點擊它草莓和香草再次出現。 – zzzzz 2013-07-24 12:26:21