多个tableview问题

时间:2012-05-15 17:32:30

标签: objective-c ios5

我已经使用名为ligatable的表视图控件实现了一个视图控制器。此表视图在名为ligaViewController.h的表视图控制器中具有其委托。表视图控件实现了一个原型单元,它设置了ligaCell.h控制器。以下是详细信息:

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];

....

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;

}

它目前给我这个错误:

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

非常感谢

1 个答案:

答案 0 :(得分:3)

使用 -

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