2014-01-28 79 views
0

原谅我对iPhone编程的无知,因为我是一个新手。 我正在做一个应用程序,其中init view controller是用于显示数据的UITable视图控制器,另一个用于输入数据的View controller。UITableviewcontroller重新加载数据问题

我的问题是,当我输入一个新的数据,它不会出现在UItable控制器,我试图重新加载数据[self.tableview reloadData]viewDidLoad但数据不会重新加载,因为我使用自定义委托我尝试写[self.tableview reloadData]作为我的自定义代理的最后一行,但它也没有工作,我尝试使用viewDidAppear,但那也不起作用。

这里是代码:

MainViewController.m(TableView中)

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSLog(@"Initializing conference array"); 

    conferenceData = [[NSMutableArray alloc]init]; 

    SavingData *loadData = [[SavingData alloc]init]; 
    NSLog(@"Loading the file then fill it in an array"); 
    conferenceData = [loadData LoadDataArray]; 

    NSLog(@"Done Initializing conference array"); 

    [self.tableView reloadData]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 

    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

    return [conferenceData count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 

    NSLog(@"writing data in cell number %i",indexPath.row); 
    cell.textLabel.text = [[conferenceData objectAtIndex:indexPath.row]name]; 

    return cell; 
} 

// Implementing the adding delegate 
-(void) setInformation:(Adding *)controller withObject:(Conference *)info 
{ 
    Conference *confer = info; //Temprory Conference object to store data 
    SavingData *saveToFile = [[SavingData alloc]init]; 

    if ([saveToFile SavingDataWithObject:confer]) //Calling SavingDataWithObject method and check if the save operation return true or false 
    { 
     NSLog(@"Done Saving !!"); 
    } 
    [self.navigationController popToRootViewControllerAnimated:YES]; // after saving return to the main window 
    NSLog(@"Should be popped right now"); 
} 

非常感谢你提前

回答

0

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

细胞可以为空在这里,所以你可能实际上并没有回应细胞。

尝试使用

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

此功能将永远不会返回零。

但是首先你必须注册什么@Cell是。另外,你也可以检查单元格是否为零,如果不是,则创建它,但我认为这种方法更清晰。如果单元格不是零,并且创建它,如果它不是,但我认为这种方法更清晰。

最后一个想法是,仔细检查一下,当您调用reloadData时,您的数组实际上已被填充,您可以在cellForRowAtIndexPath中设置一个断点以确保它被称为适当的次数。

0

我发现这个问题

显然,当我在-viewWillAppear法正常工作表重新载入数据写的代码。

非常感谢你帮助我