【问题标题】:How to add submenu's in table view in ios如何在ios的表格视图中添加子菜单
【发布时间】:2013-08-12 10:51:09
【问题描述】:

我不知道这个问题是否问过,但我仍在寻找答案。我正在研究 tableview 概念,我正在创建一个表格视图,就像一些菜单一样,如收件箱、已发送、设置等。现在我想要什么我是否想在每个菜单中创建子菜单,例如,如果我单击收件箱,它应该为我要创建子菜单的每个主菜单显示新的、已回复的、已删除的等。使用数组,我们可以通过检查部分加载,但不使用数组我想直接创建一个值得注意的我使用自定义单元格的我还想根据菜单显示图像,如果它是收件箱我必须显示收件箱图像。谁能帮帮我??

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

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

}

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

    static NSString *cellidentifier=@"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)
    {
        cell.MyHomeMenuLabel.text=@"Inbox";
    }



}

【问题讨论】:

    标签: ios uitableview custom-cell


    【解决方案1】:

    这里有一个很好的 tuts 它可以帮助你:

    Expanding/Collapsing TableView Sections

    Expandable UITableView

    Oliver Letterer 的这个 github 代码 here。

    【讨论】:

      【解决方案2】:

      您可以创建一个 UITableview,其中包含您所说的收件箱、发送、设置等单元格。

      在您需要创建另一个 UITableView 之后,它将包含您的子菜单按钮或标签,例如点击收件箱时新建、回复、删除。

      同样,您将对主 UITableView 中的其余单元格执行此操作。

      不要对我将如何确定哪个 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
      

      【讨论】:

      • 在本地创建新的 tableView 会更容易,而不是处理自定义单元格以及您想要创建自定义单元格的内容?
      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-04
        • 1970-01-01
        相关资源
        最近更新 更多