UITableView 中两个不同的 UITableViewCell [英] Two different UITableViewCell in UITableView

查看:22
本文介绍了UITableView 中两个不同的 UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个包含 2 个部分行的 TableView.此表有 2 个部分(第一部分有 1 个单元格,第二部分有 3 个单元格)

I want to create one TableView that has 2 section rows. this table has 2 section (first section has 1 cell and second section has 3 cell)

注意:第一节的单元格与第二节的单元格不同.

notice:cell of first section different with cells of second section.

这是我的代码,但不起作用!!!

this is my code but don't working!!!

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

    NSArray *name = [_names objectForKey:key];
    static NSString *CellIdentifier2 = @"CustomerCell";

    if (indexPath.section == 0) {

        static NSString *CellIdentifier = @"myCell";
        FirstCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[FirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        // Configure the cell...
        cell.nameLable.text = [NSString stringWithFormat:@"blue"];
        cell.numberLable.text = [NSString stringWithFormat:@"1212432543"];
        cell.profileImage.image = [UIImage imageNamed: @"profile.png"];

        return cell;
//this part not working !!! XD

    }
    else if (indexPath.section >= 1) {

        CustomerCell *cell = (CustomerCell *)[self.table dequeueReusableCellWithIdentifier:CellIdentifier2];
        if (cell == nil)
        {
            NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"CustomerCell" owner:nil options:nil];

            for (id currentObject in topLevelObject) {
                if ([currentObject isKindOfClass:[CustomerCell class]]) {
                    cell = (CustomerCell *)currentObject;
                    break;
                }
            }
        }
        // Configure the cell...
        cell.titleLable.text = [name objectAtIndex:indexPath.row];
        return cell;
    }
    return nil;
}

customerCell &FirstCell 是用于自定义单元格的两个 UITableViewCell.当我只运行这段代码时,第一个部分不起作用并且不显示单元格但另一部分正在工作,请指导我并告诉我我的错误在哪里.

customerCell & FirstCell are tow UITableViewCell for custom cells. when I to do run this code only section one not working and don't show cell but another section is working please guide me and tell me where is it my mistake.

推荐答案

试试这个:

FirstCell *cell = (FirstCell *)[tableView dequeueReusableCellWithIdentifier:strEvalIdentifier]; 
if (cell == nil)
{
   NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FirstCell" owner:self options:nil];
   cell = [nib objectAtIndex:0];
} 

这篇关于UITableView 中两个不同的 UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆