androniennn
androniennn

Reputation: 3137

Two TableViews with two CUSTOM cells in ONE view

I have written some code to display two tableviews' data with two custom cells in one view:

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UIImage *image;

    static NSString *CellIdentifier= @"Cell";
        UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if(!cell) {
            cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
     if (tableView==self.eqALineup){
         static NSString *CellIdentifier= @"eqa";
         LineupACell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

         if(!cell) {
             cell =[[LineupACell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

             cell.joueur.text=[arrayofJoueura objectAtIndex:indexPath.row];
         }

     }


    else {
        static NSString *CellIdentifier= @"eqb";
        LineupBCell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if(!cell) {
            cell =[[LineupBCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
             cell.joueur.text=[arrayofJoueurb objectAtIndex:indexPath.row];
        }
}

    return cell;
}

The problem is no data displayed in the two table views. Thank you for helping.

Upvotes: 0

Views: 72

Answers (1)

CocoaEv
CocoaEv

Reputation: 2984

without really diving into your problem, could you try to move this code to outside your check:

Move:

    if(!cell) {
        cell =[[LineupBCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
         cell.joueur.text=[arrayofJoueurb objectAtIndex:indexPath.row];
    }

To:

    if(!cell) {
        cell =[[LineupBCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];  
    }
    cell.joueur.text=[arrayofJoueurb objectAtIndex:indexPath.row];

also - I'm assuming that you have that "joueur" property defined in your subclass and it is associated via an outlet with a UILabel?

That may be the other issue: make sure your property is associated with a label in your prototype cell.

hope that helps.

Upvotes: 1

Related Questions