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

我已经tabBarController在我的项目中添加了。有一个tabBarItem调用ContactsViewController它具有带有 customCell 的 tableView。当我单击 tableViewRow 时,它会将我带到下一个视图。然后我单击另一个 tabBarItem 并再次单击ContactsViewController我收到错误,因为UITableViewdataSource 必须返回一个单元格tableView:cellForRowAtIndexPath。我的代码有什么问题?

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

    }

在我在 Appdelegate.mi 中添加上述方法后,我得到了异常

4

2 回答 2

0

改变 :

 return 0;

至 :

 return nil;
于 2013-03-12T05:30:08.537 回答
0

表没有获取您的自定义单元格。检查您的 ContactCustom cell.xib 并将您的 ContactCustom 添加为单元格的类。
在此处输入图像描述

添加您的自定义类名称而不是“DeckListCell”。

尝试这个:

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;
 }  
于 2013-03-12T05:33:46.630 回答