Pankaj Bhardwaj
Pankaj Bhardwaj

Reputation: 2131

Custom UITableViewCell not visible, My first custom cell is visible others are not

*There are so many same questions available and I have seen almost all to solve this issue but couldn't get correct answer. I have to add some custom tableview cells in a UITableView, So I have created custom cells and register them in the viewDidLoad function.

 typedef enum {
    rProduct,
    rAddMoreItem,
    rItem,
    rBill,
    rApplyCoupon,
    rGrandTotal,
    rBottomInfo,
    rNumerOfRows
} SectionType;

     [myTableView registerNib:[UINib nibWithNibName:[FPMCartTableViewCell tableViewIdentifier] bundle:nil]
          forCellReuseIdentifier:[FPMCartTableViewCell tableViewIdentifier]];

     [myTableView registerNib:[UINib nibWithNibName:[FPMAddMoreItemsTableViewCell tableViewIdentifier] bundle:nil]
          forCellReuseIdentifier:[FPMAddMoreItemsTableViewCell tableViewIdentifier]];

     [myTableView registerNib:[UINib nibWithNibName:[FPMItemTableViewCell tableViewIdentifier] bundle:nil]
          forCellReuseIdentifier:[FPMItemTableViewCell tableViewIdentifier]];

     [myTableView registerNib:[UINib nibWithNibName:[FPMApplyCouponTableViewCell tableViewIdentifier] bundle:nil]
          forCellReuseIdentifier:[FPMApplyCouponTableViewCell tableViewIdentifier]];


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

    int noOfRows = 0;
    switch (section) {
        case rProduct:
            noOfRows = 2;
        break;
        case rAddMoreItem:
            noOfRows = 1;
            break;
        case rItem:
            noOfRows = 3;
            break;
        case rBill:
            noOfRows = 1;
            break;
        case rApplyCoupon:
            noOfRows = 1;
            break;
        case rGrandTotal:
            noOfRows = 1;
            break;
        case rBottomInfo:
            noOfRows = 1;
            break;
    }
    return noOfRows;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return rNumerOfRows;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;   
}
And added in the cellForRowAtIndexPath method :
    {

    UITableViewCell *cell;
        switch (indexPath.section) {
            case rProduct:
            {
                NSString *identifer = [FPMCartTableViewCell tableViewIdentifier];
                FPMCartTableViewCell *cell1 = (FPMCartTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer];
                if (!cell1)
                {
                    cell1 = [[FPMCartTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
                }
                [self configureCell:cell1 forIndexPath:indexPath];
                cell = cell1;
            }
                break;
            case rAddMoreItem:
            {
                NSString *identifer = [FPMAddMoreItemsTableViewCell tableViewIdentifier];
                FPMAddMoreItemsTableViewCell *cell2 = (FPMAddMoreItemsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer];
                if (!cell2)
                {
                    cell2 = [[FPMAddMoreItemsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
                }
                cell2.backgroundColor = [UIColor redColor];
                cell = cell2;
            }
                break;
            case rItem:
            {
                NSString *identifer = [FPMItemTableViewCell tableViewIdentifier];
                FPMItemTableViewCell *cell1 = (FPMItemTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer];
                if (!cell1)
                {
                    cell1 = [[FPMItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
                }
                cell = cell1;
            }
                break;
            case rBill:
            {
                NSString *identifer = [FPMItemTableViewCell tableViewIdentifier];
                FPMItemTableViewCell *cell1 = (FPMItemTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer];
                if (!cell1)
                {
                    cell1 = [[FPMItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
                }
                cell = cell1;

            }
                break;
            case rApplyCoupon:
            {
                NSString *identifer = [FPMApplyCouponTableViewCell tableViewIdentifier];
                FPMApplyCouponTableViewCell *cell1 = (FPMApplyCouponTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer];
                if (!cell1)
                {
                    cell1 = [[FPMApplyCouponTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
                }
                cell = cell1;
            }
                break;
            case rGrandTotal:
            {
                NSString *identifer = [FPMItemTableViewCell tableViewIdentifier];
                FPMItemTableViewCell *cell1 = (FPMItemTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifer];
                if (!cell1)
                {
                    cell1 = [[FPMItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
                }
                cell = cell1;
            }
                break;
            case rBottomInfo:
            {
                if(!cell){
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
                }
                cell.textLabel.text = @"Select Delivery and payment options in next step";
            }
                break;
        }
    [cell setHidden:NO];
    return cell;
    }

But only first cell is visible and last cell which one is simple one not othetrs. enter image description here

I have tried to log but it comes hidded = true by default

(lldb) po cell
<FPMApplyCouponTableViewCell: 0x7f97ec067e00; baseClass = UITableViewCell; frame = (0 402; 375 100); hidden = YES; autoresize = W; layer = <CALayer: 0x600000238be0>>

Upvotes: 1

Views: 64

Answers (1)

Pankaj Bhardwaj
Pankaj Bhardwaj

Reputation: 2131

Its working now I have just did a minor change in each cell alloc line.

            if (!cell1)
            {
                cell1 = [[FPMCartTableViewCell alloc] init];
            }

and its working thanks for your efforts.

Upvotes: 1

Related Questions