ios – 在UITableView中设置多个部分

我已经设置了自定义单元格的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;


        }
    }
}

解决方法

您可以在其中定义部分和行的数量,如下所示:
- (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;
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...