0

在我的 firstViewcontroller 中,我构建了一个 tableview。它的数据来自数据库。在 secondviewcontroller 中,我在数据库中插入数据,并从 firsviewcontroller 调用函数来构建字典数据,就像在 firstviewcontroller 中提取数据一样。所有数据都是从数据库中恢复,但无法重新加载 tableview。我无法访问 cellForRowAtIndexPath 甚至 numberofrowsinsection>0

这就是我所做的:

Secondviewcontroller: 
//I insert data in database and I instanciate class where my tableview is and call refresh method

first = [[FirstviewController alloc]initWithNibName:@"FirstviewController" bundle:nil];

[first refreshList];

//in Firstviewcontroller

-(void)refreshList{

   self.tableview= [[[UITableView alloc] initWithFrame:self.view.bounds] autorelease];
    tableview.dataSource = self;
    tableview.delegate = self;

     NSMutableArray *array = [[NSMutableArray alloc] init];
//I recover my data from data base

    IPADAGRIONEActivityList *arrayActivities = [IPADAGRIONEActivity findAll];

    if ([arrayActivities length] > 0)
    {
        for (IPADAGRIONEActivity * oneRec in arrayActivities)
        {
            [array addObject:oneRec];


        }
    }
    //activities is NSMutablearray that contains all my data
    self.activities = array;
 //I build dictionnary 
    [self buildObjectsDictionnary:activities

    NSLog(@"self.act%@",self.tableview);
    [array release];
  [self.tableview reloadData];
}

//numberofrowsinSection: 
          NSLog(@"rows%d",[[objects objectForKey:[objectsIndex objectAtIndex:section]] count]);
            return   [[objects objectForKey:[objectsIndex objectAtIndex:section]] ;


//numberOfSection: 

NSLog(@"nbre of section%d",[objectsIndex count]);
                return [objectsIndex count];}


//CellforRowatInddexPath: It dosen't access to this method

if (cell== nil) {
                cell = [[MHCActivityListCell alloc]init];

            }
            IPADAGRIONEActivity *activite ;

                    cell.activityCategory.text = [NSString stringWithFormat:@"%@", [activite EMAIL]];
                }

            }
4

1 回答 1

0

It looks like self.tableView is not actually visible. You re-initialize it in refreshData but you do not add it as a subview again with [self.view addSubview:self.tableView].

As I said before, IT IS INCORRECT AND BAD USAGE to re-initialize the tableView, but it looks like thats the problem.

cellForRowAtIndexPath does not get called because the tableview is not visible so it doesn't try to display cells.

于 2013-08-01T18:07:31.997 回答