ios - 如何在 tableview iOS 中设置节标题而不重复数据?

标签 ios objective-c uitableview

我有一个 TableView ,现在我正在初始化表,

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [arr count]+1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [arr count]+1;
}

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

    NSUInteger row = [indexPath row];
    if (row == 0) 
    {
        UITableViewCell *cell = [[UITableViewCell alloc] init];
        return cell;
    }
    else
    {
        static NSString *CellIdentifier = @"moduleCell";
        MyTableViewCell *cell = (MyTableViewCell*)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];

        if (cell == nil) 
        {

            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];

            cell.backgroundColor = [UIColor clearColor];
            cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

        }
        current = [arr objectAtIndex:indexPath.row-1];
        [cell setCellDetails:arr WithIndex:row-1 withParentView:self];
        return cell;
    }
}

当我在我的表格 View 中重复执行此数据时。在我这样做之前,我做了,

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

这是有效的,但我需要设置像标题这样的节标题。那么有没有办法设置section headers而不重复数据呢?

最佳答案

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.section == 0){//for first section

    }else if(indexPath.section == 1){//for second section

    }
}

关于ios - 如何在 tableview iOS 中设置节标题而不重复数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35692425/

相关文章:

iphone - UIView 子类的 Dealloc 方法没有被调用

ios - NS_AVAILABLE(10_10, 8_0) 在为 iOS 7 构建时导致崩溃

objective-c - 添加 subview 时 Tab 键不起作用

swift - tableView 或 collectionview dequeue 可重复使用如何快速工作

objective-c - UITableView 在 iOS 7.1 上无法正确重新加载

ios - 如何从 NSURLSessionDataTask 完成处理程序返回 NSData

ios - 在标签栏应用程序中更改 "more"图标

ios - UITableView 动态单元格高度仅在滚动后才正确

swift - 如何在 Swift 的 tableView 中仅显示从字典中获取的某些单元格

objective-c - 在 iOS 中传递参数