在我的firstViewcontroller中,我构建了一个tableview.Its数据来自数据库。在secondviewcontroller中我将数据插入到数据库中,我从firsviewcontroller调用函数来构建dictionnary数据,就像我在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]];
}
}
答案 0 :(得分:0)
看起来self.tableView
实际上并不可见。您可以在refreshData
重新初始化它,但不要再使用[self.view addSubview:self.tableView]
将其添加为子视图。
正如我之前所说,重新初始化tableView是不正确和糟糕的用法,但看起来这就是问题所在。
不会调用cellForRowAtIndexPath,因为tableview不可见,因此它不会尝试显示单元格。