2013-04-27 65 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