0
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";

    if (tableView ==tableview1) {
        ContactCustom *cell1=(ContactCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

        if (cell1 == nil) {
            [[NSBundle mainBundle] loadNibNamed:@"ContactCustom" owner:self options:nil];
            cell1 = contactCustom;
        }



        NSString *nameStr = [newcontactList objectAtIndex:indexPath.row];
        NSArray * arr = [nameStr componentsSeparatedByString:@"!"];
        NSLog(@"arr %@\n",arr);

        [cell1 ContactNameText:[arr objectAtIndex:0]];
        [cell1 MobileNoText:[arr objectAtIndex:1]];

        if (![[arr objectAtIndex:3] isEqualToString:@"no"]) {
           [cell1 ScreenNameText:[arr objectAtIndex:3]]; 
        }

        if (![[arr objectAtIndex:4] isEqualToString:@"0"]) {
            [cell1 setImg:[arr objectAtIndex:4]];
        }
        else
        {
            cell1.receiveCountBtn.hidden=YES;
        }

        cell1.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        cell1.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell1;
    }

    else if (tableView ==tableview2) {

        ContactPicsCustom *cell=(ContactPicsCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

        if (cell == nil) {
            [[NSBundle mainBundle] loadNibNamed:@"ContactPicsCustom" owner:self options:nil];
            cell = contactPicsCustom;
        }

        NSString *nameStr = [sentPicsContactList objectAtIndex:indexPath.row];
        NSArray * arr1 = [nameStr componentsSeparatedByString:@"!"];
//        NSLog(@"arr1 %@\n",arr1);

        User *userObj = [[User alloc]init];
        userObj.fName = [arr1 objectAtIndex:0];
        userObj.mNo = [arr1 objectAtIndex:1];

//        NSLog(@"user %@ %@\n",userObj.fName,userObj.mNo);

        [cell ContactNameText:[arr1 objectAtIndex:0]];

        if ([arr1 count] == 4) {
            [cell ScreenNameText:[arr1 objectAtIndex:3]];
        }

//        [cell setImg:[dicPhotosCount valueForKey:[arr1 objectAtIndex:0]]];
        NSInteger cnt = [[DBModel database]photosCnt:userObj];
//        NSLog(@"cnt: %d\n",cnt);
        if(cnt >= 1)
        {
            [cell setImg:[NSString stringWithFormat:@"%d",cnt]];
        }
        else
        {
            cell.imgView.hidden=YES;
        }

        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }

        return 0;
}

I have added tabBarController in my project.There is one tabBarItem called ContactsViewController which has tableView with customCell.When I click on the tableViewRow it takes me to next view.then I click someother tabBarItem and again click ContactsViewController i am getting error as UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath.What is wrong with my code?

-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if (tabBarController.selectedIndex == 0) {

    }
    else if (tabBarController.selectedIndex == 1) {

 UINavigationController *requiredNavigationController = [tabBarController.viewControllers objectAtIndex:1];
        [requiredNavigationController popToRootViewControllerAnimated:YES];

    }

after i added above method in Appdelegate.m i am getting excepion

user2134883
  • 255
  • 1
  • 2
  • 9

2 Answers2

0

Change :

 return 0;

To :

 return nil;
Rushi
  • 4,553
  • 4
  • 33
  • 46
0

Table is not getting your custom cell.Check your ContactCustom cell.xib and add your ContactCustom as the class of the cell.
enter image description here

add your custom class name instead of "DeckListCell".

try this:

if (tableView ==tableview1) {
            ContactCustom *cell1=(ContactCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) 
    { 
       NSArray *nib;
       nib= [[NSBundle mainBundle] loadNibNamed:@"ContactCustom" owner:self  options:nil];
        for (id oneObject in nib) if ([oneObject isKindOfClass:[ContactCustom class]])
                cell = (ContactCustom *)oneObject;

       // configure your cell.
    }
  return cell;
 }  
KDeogharkar
  • 10,939
  • 7
  • 51
  • 95
  • no.still it gives same error.i edited my code above.did u see it? – user2134883 Mar 12 '13 at 06:06
  • will you please debug and check on which table it is happen? table1 or table2 – KDeogharkar Mar 12 '13 at 06:14
  • In contactsViewController i display list of contacts.When user selects particular contact it takes to the next view where list of images for that contact.If no images are there i am getting exception.It is with table1 – user2134883 Mar 12 '13 at 06:32