reloadData方法没有从另一个类调用

时间:2022-03-14 06:25:47

I will directly start from an ex: I have two classes A and B, both are derived from UITableViewController.

我将直接从ex开始:我有两个类A和B,都是从UITableViewController派生的。

I have also added them into navigation controller so there is navigation going on from A to B. These both classes use database for showing data into the table. Now in B View I delete a row from the DB and A view displays the row count of that DB table. Now what I am doing is on the BACK button of the navigation I want to I am calling this method TRY 1:

我还将它们添加到导航控制器中,因此从A到B进行导航。这两个类都使用数据库将数据显示到表中。现在在B视图中,我从数据库中删除一行,一个视图显示该数据库表的行数。现在我正在做的是导航的BACK按钮我想要我调用这个方法TRY 1:

//in class B
-(IBAction)backBtnPressed
{
[ObjA.tbleView reloadData];
[self.navigationController popViewControllerAnitmated:YES]; 
}

on its action. The problem is this method does not reload the data of View A. i.e., it doesn't call the tbleView's delegate methods like cellForIndexPath...etc. Then I thought that may the reloadData shud be called from the same class so did this TRY 2:

在它的行动。问题是这个方法没有重新加载View A的数据,即它没有调用tbleView的委托方法,如cellForIndexPath ...等。然后我认为可以从同一个类调用reloadData shud,所以这个TRY 2:

//in class B
-(IBAction)backBtnPressed
{
[ObjA.tbleView myReloadData];
[self.navigationController popViewControllerAnitmated:YES]; 
}
//Class A
-(void)myReloadData
{
[self.tbleView reloadData];
}

It comes into this method but still doesn't call the tableView delegate methods. Please let me know why I am not able to do this silly thing :(. Regards.. Amit

它涉及此方法但仍然不调用tableView委托方法。请让我知道为什么我不能做这个愚蠢的事情:(。问候......阿米特

2 个解决方案

#1


Have you connected the UITableView's delegate and dataSource outlets correctly (either in your nib or using code, depending on how you create the table)?

您是否正确连接了UITableView的委托和dataSource出口(在您的笔尖中或使用代码,具体取决于您创建表的方式)?

#2


You're close, put this in class A:

你很接近,把它放在A级:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.tableView reloadData];
}

#1


Have you connected the UITableView's delegate and dataSource outlets correctly (either in your nib or using code, depending on how you create the table)?

您是否正确连接了UITableView的委托和dataSource出口(在您的笔尖中或使用代码,具体取决于您创建表的方式)?

#2


You're close, put this in class A:

你很接近,把它放在A级:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.tableView reloadData];
}