2013-08-12 52 views
2

我不知道这个问题是否有问题,但我仍然在寻找答案。我在tableview概念中工作,并且创建了一个类似于一些菜单的收件箱,发送,设置etc.Now我想要的是我想创建子菜单的内部每个菜单,例如,如果我单击收件箱它应该显示新的,回复,删除等这样的每个主菜单我想创建子菜单。使用数组,我们可以加载通过检查部分,但没有使用数组我想直接创建和着名的一个我已经使用自定义单元格我也想显示图像按菜单,如果它是收件箱我必须显示收件箱图像。任何人都可以帮助我吗?如何在ios中的表格视图中添加子菜单

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 8; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 8; 

} 

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

    static NSString *[email protected]"ViewProfileCell"; 

    MyHomeViewCell *cell= [[MyHomeViewCell alloc] init]; 

    cell=(MyHomeViewCell*)[tableView dequeueReusableCellWithIdentifier:cellidentifier]; 

    if(!cell) 
    { 
NSArray *nibofMyHomeCell=[[NSBundle mainBundle]loadNibNamed:@"MyHomeViewCell" owner:self options:Nil]; 
     cell=[nibofMyHomeCell objectAtIndex:0]; 


    } 

    if(indexPath.section==0) 
    { 
     [email protected]"Inbox"; 
    } 



} 

回答

0

有很多方法可以做到这一点。例如,您可以将每个项目显示为区域标题,并且如果轻触区域标题,则显示(或隐藏)该区域中的所有行。这些行是“子菜单”项目(新建,回复,删除)。或者您可以为每个部分使用不同的部分以及如何或隐藏部分。或者显示并隐藏行。这几乎都是通过更改节和行数来控制的。

1

如你所说的收件箱,发,设置等

后,您需要创建另一个UITableView的其中将包含如新的子菜单按钮或标签,您可以创建一个UITableView其中将包含在它的细胞,回复,删除当点击收件箱时。

Simillarly你会为你的主UITableView中的其他单元做些什么。

不要混淆我如何识别哪个tableview会被调用。

您将检查的tableview名象下面这样:

if(tableView==main) 
    { 
    ///Code for main menu tableview. 
    } 
    else if(tableView==sub) 
    { 
    ////Code for submenu tableview. 
    } 

这个你将在所有的UITableView委托和数据源的方法做:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
+0

期望创建新的tableview不能用自定义单元格吗? –

+0

创建新的tableView将在本地更容易,而不是处理自定义单元格以及您想要创建自定义单元格的内容? –

相关问题