简体   繁体   English

UITableView中的两个不同的UITableViewCell

[英]Two different UITableViewCell in UITableView

I want to create one TableView that has 2 section rows. 我想创建一个具有2个节行的TableView。 this table has 2 section (first section has 1 cell and second section has 3 cell) 该表有2个部分(第一个部分有1个单元格,第二个部分有3个单元格)

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 are tow UITableViewCell for custom cells. customerCellFirstCell是用于自定义单元格的两个UITableViewCell 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. 当我执行此代码时,只有一节不起作用,并且不显示单元格,而另一节正在起作用,请指导我并告诉我这是我的错误在哪里。

Try this: 尝试这个:

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

Try using the same code as in the second cell. 尝试使用与第二个单元格相同的代码。

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

        for (id currentObject in topLevelObject) {
            if ([currentObject isKindOfClass:[FirstCell class]]) {
                cell = (FirstCell *)currentObject;
                break;
            }
        }
// Configure the cell...
    cell.nameLable.text = [NSString stringWithFormat:@"blue"];
    cell.numberLable.text = [NSString stringWithFormat:@"1212432543"];
    cell.profileImage.image = [UIImage imageNamed: @"profile.png"];

    return cell;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 两个UIViewControllers的不同UITableView中的一个自定义UITableViewCell - One Custom UITableViewCell in different UITableView of two UIViewControllers 如何在UITableView中使用两个不同的Custom UITableViewCell? - How can I use two different Custom UITableViewCell's in a UITableView? 将UITableViewCell从另一个UITableView出队 - Dequeuing a UITableViewCell from a different UITableView 两种UITableViewCell,两种与JSON不同的数组。 如何填充UITableView? - Two kind of UITableViewCell , Two Different Arrays from JSON . How to Populate the UITableView? UITableView背景色与UITableViewCell不同 - UITableView Background Color Different From UITableViewCell 如何从不同的 UIViewController 中的 UITableView 访问 UITableViewCell? - How to access UITableViewCell from UITableView in different UIViewController? 使用不同种类的UITableViewCell的UITableView最佳实践 - Best practice in UITableView with different kind of UITableViewCell 如何在一个Uitableview中添加两个笔尖UITableViewCell - How to add a two nib UITableViewCell in one Uitableview 应用在同一UITableView中的两个自定义UITableViewCell崩溃 - App crashes with two custom 'UITableViewCell' in the same 'UITableView' 故事板上的两个具有不同标识符和不同高度的UITableViewCell - Two UITableViewCell with different identifier and different height in storyboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM