I have 2 classes, classA and classB
In classA I have a tableview that works and refreshes on demand. all the delegates and datadource are fine and there's also a property @property (nonatomic, retain) UITableView *myTableView;
I don't want to put reloadData in viewDidAppear or viewWillAppear of classA.
I want to fire [myTable reloadData] from classB.
Thanks
Use delegates to reload your tableview.
In the class where the tableview is, write this in viewDidLoad:
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateLeftTable"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(checkRes:) name:@"updateLeftTable" object:nil];
Then in the same class implement its function like so:
-(void)checkRes:(NSNotification *)notification
{
if ([[notification name] isEqualToString:@"updateLeftTable"])
{
[_rearTableView reloadData];
}
}
Finally, in the class from where you want to reload your tableview paste the following line (It's important that this line goes in the method from where you want to reload your tableview):
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateLeftTable" object:self];
Tell me if you have any problems.
When you call classA *test = [[classA alloc]init]; , it creates a new object of your class A and it has nil value for every variables you declare in this class. Thats why your reloaddata is not called becoz your array has nil value for this object which you are using to reload the table.
You have to use delegate to pass the object of from class A to class B. And then try to reload the table from this delegate object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With