views:

17

answers:

0

Hi All,

I am facing very strange problem. I have a View Controller with a table View. When code works on simulator and device on "DEBUG" mode than everything works fine. But when I run it on release mode on device then I got an exception which says tableView: cellForRowAtIndexPath must return a cell. This thing does not happen on simulator in release mode.

I am not able to understand why it is happening. Any help will be appreciated.

Thanks.

  - (UITableViewCell*)loadCell
 {

    if (arrangeBooksByName) {
        [[NSBundle mainBundle] loadNibNamed:@"TableViewCellWithInfoButton" owner:self options:nil]; 
    }
    else if (arrangeBooksByAuthor){
        [[NSBundle mainBundle] loadNibNamed:@"TableViewCellWithDetailDiscloser" owner:self options:nil];
    }
    else if (arrangeBooksByGroup){
        [[NSBundle mainBundle] loadNibNamed:@"TableViewCellWithDetailDiscloser" owner:self options:nil];
    }

    return tableViewCell;



    } 


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

    static NSString *CellIdentifier = @"CustomCellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

       if(cell == nil)
    { 
            cell = [self loadCell];
    }


    if (arrangeBooksByName) {

        bookTitle = (UILabel *)[cell.contentView viewWithTag:1];
        bookCreator = (UILabel *)[cell.contentView viewWithTag:2];
        numberOfBooksLabel = (UILabel *)[cell.contentView viewWithTag:4];   
        infoButton = (UIButton*)[cell.contentView viewWithTag:5];

        [infoButton addTarget:self action:@selector(displayInfoPage:) forControlEvents:UIControlEventTouchUpInside];
        infoButton.tag = indexPath.row;

        bookTitle.text = [[fileInformationArray objectAtIndex:indexPath.row] objectForKey:@"title"];
        bookCreator.text = [[fileInformationArray objectAtIndex:indexPath.row] objectForKey:@"creator"];
        numberOfBooksLabel.text = @"";

    }
    else if(arrangeBooksByAuthor){

        bookTitle = (UILabel *)[cell.contentView viewWithTag:1];
        bookCreator = (UILabel *)[cell.contentView viewWithTag:2];
        numberOfBooksLabel = (UILabel *)[cell.contentView viewWithTag:4];   
        detailDiscloser = (UIButton*)[cell.contentView viewWithTag:5];

        [detailDiscloser addTarget:self action:@selector(diplayBookOfSelectedAuthor:) forControlEvents:UIControlEventTouchUpInside];
        detailDiscloser.tag = indexPath.row;

        bookTitle.text = [authorsNameArray objectAtIndex:indexPath.row];
        bookCreator.text = @"";

        int count = 0;
        for (int i=0; i < [fileInformationArray count]; i++) {
            if ([[[fileInformationArray objectAtIndex:i] objectForKey:@"creator"] isEqualToString:bookTitle.text]) {
                count++;
            }
        }
        numberOfBooksLabel.text = [[@"< " stringByAppendingString:[NSString stringWithFormat:@"%d",count]] stringByAppendingString:@" >"];

    }
    else if (arrangeBooksByGroup) {

        bookTitle = (UILabel *)[cell.contentView viewWithTag:1];
        bookCreator = (UILabel *)[cell.contentView viewWithTag:2];
        numberOfBooksLabel = (UILabel *)[cell.contentView viewWithTag:4];   
        detailDiscloser = (UIButton*)[cell.contentView viewWithTag:5];

        [detailDiscloser addTarget:self action:@selector(diplayBookOfSelectedAuthor:) forControlEvents:UIControlEventTouchUpInside];
        detailDiscloser.tag = indexPath.row;

        bookTitle.text = [groupNameArray objectAtIndex:indexPath.row];
        bookCreator.text = @"";

        int count = 0;
        for (int j=0; j < [fileInformationArray count]; j++) 
        {
            if ([[[fileInformationArray objectAtIndex:j] objectForKey:@"group"] isEqualToString:[groupNameArray objectAtIndex:indexPath.row]]) {
                count++;
            }

        }

        numberOfBooksLabel.text = [[@"< " stringByAppendingString:[NSString stringWithFormat:@"%d",count]] stringByAppendingString:@" >"];



    }

return cell;



   }