8

我已经设置了一个带有自定义单元格的 uitableview。

我想把这些分成带标题的部分。查看下面的照片,我正在寻找以下布局:

部分 - 我的个人资料自定义单元格 - wwwwwwwwwwwwww...
部分 - 应用程序
自定义单元格 - 游戏
自定义单元格 - 共享
自定义单元格 - 评分
自定义单元格 - 设置
自定义单元格 - 帮助
自定义单元格 - 注销

我可以看到如何添加一个部分并控制一个部分中的行,但这会将单元格复制到多个部分中,我不知道如何让一个部分有一行,而另一个部分有 6 行。我还想为这些部分设置样式以显示,有点像 Facebook 菜单样式。

我应该为实际部分创建自定义单元格并且对部分(单元格)选择没有任何操作吗?

这是 UITableView 的代码

static NSString *CellIdentifier = @"Cell";
LeftMenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

    NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"LeftMenuTableViewCell" owner:nil options:nil];

    for (UIView *view in views) {
        if([view isKindOfClass:[UITableViewCell class]]) {
            cell = (LeftMenuTableViewCell*)view;


        }
    }
}

在此处输入图像描述

4

1 回答 1

22

您可以在其中定义节数和行数,如下所示:

- (UIView *) tableview:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{
    UIView view;
    if(section == 0) {
         // Initialise view for section 1
    } else {
         // Initialise view for section 2
    }
}

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

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return ((section == 0) ? 1 : 6);
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    // return appropriate cell(s) based on section
    if(indexPath.section == 0) 
    {
        // Return 1 cell
    }
    else if(indexPath.section == 1) 
    {
        switch(indexPath.row) {
            case 0: // Initialize cell 1
                    break;
            case 1: // Initialize cell 2
                    break;
            ...
        }
    }
    return cell;
}
于 2012-11-15T22:25:47.977 回答