IPhone table cell problem


I am creating the table in the loadView method because I need to resize it, and I am creating the cells in a nib to make it easier to edit them.

I keep getting the error below that I was not getting when my table was created in the nib.

UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath

Code I believe is causing the error.

- (void)loadView
    // Set the size for the table view
    CGRect tableViewRect = CGRectMake(0, 30, 320, 436);

    // Create a table viiew
    UITableView *tableView = [[UITableView alloc] initWithFrame:tableViewRect style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;    

    // This view contains the table view and the status bar
    UIView *totalView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    [totalView addSubview:tableView];
    self.view = totalView;
    [tableView release];

    [totalView release];

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return cellOne;
        else {
            return cellTwo;
    else if (indexPath.section == 1) {
        return cellThree;
    else {
        return cellFour;

If you override -(void)loadView, the nib file will not be loaded. This is assuming that cellOne etc. are IBOutlet properties. If you want to create your table view manually, you should delete your -(void)loadView method, and move the code to -(void)viewDidLoad