theomen
theomen

Reputation: 919

Multiple tableview issue

I have implemented a view controller with a table view controll called ligatable. This table view has its delegate in a table view controller called ligaViewController.h. Table view control has implemented one prototype cell, that has set ligaCell.h controller. Here are the details:

competicionViewController.h

#import "ligaViewController.h"

@interface CompeticionViewController : UIViewController 
{

    IBOutlet UITableView *ligaTable;
    ligaViewController *ligaController;

}

@property (strong, nonatomic) IBOutlet UITableView *ligaTable;
@property (strong, nonatomic) ligaViewController *ligaController;

competicionViewController.h

- (void)viewDidLoad
{
...

 ligaController = [[ligaViewController alloc] init];

    [ligaTable setDelegate:ligaController];
    [ligaTable setDataSource:ligaController];

....

And the delegate method in ligaViewController:

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

        ligaCell *cell = [self.tableView
                          dequeueReusableCellWithIdentifier:@"posicion"];


        NSDictionary *posicion = [[NSDictionary alloc] initWithDictionary: [ligaArray objectAtIndex:indexPath.row]];

        cell.posicion.text = [posicion valueForKey:@"posicion"];

        cell.PJ.text = [posicion valueForKey:@"pj"];

        cell.PG.text = [posicion valueForKey:@"pg"];

        cell.PP.text = [posicion valueForKey:@"pp"];

        cell.PF.text = [posicion valueForKey:@"favor"];

        cell.PC.text = [posicion valueForKey:@"contra"];

        return cell;

}

It is currently giving me this error:

terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

Many thanks

Upvotes: 0

Views: 35

Answers (1)

rishi
rishi

Reputation: 11839

Use -

ligaCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"posicion"];
if (cell == nil)
{ 
    cell = [[[ligaCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier] autorelease];
}

Upvotes: 3

Related Questions