gowtham gowtham - 11 days ago 5
Objective-C Question

TableView reload data is not working when it is called from other class

I have two class ,

class A
with container and
UISegmentControl
in
class B
I have a
UITableView
which is embedded with the container.
Initially when loading data the
UITableView
is loading properly when I choose different button in the
UISegmentControl
I did reloading in
class B
for which table reloading is not happening!

Class A with Container

@implementation UpgradeVCViewController
int flag = nil;

- (void)viewDidLoad {

[super viewDidLoad];
_containerView.alpha = 1.0;
// Do any additional setup after loading the view.
HHSlideView * slideView = [[HHSlideView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height -64) ];
slideView.delegate = self;

[_iconView addSubview:slideView];
[self.view addSubview:_containerView];

-(NSInteger)numberOfSlideItemsInSlideView:(HHSlideView *)slideView
{
return 3;
}

-(NSArray *)namesOfSlideItemsInSlideView:(HHSlideView *)slideView
{
NSArray *items = [[NSArray alloc]initWithObjects:@"PREMIUM ECONOMY",@"BUSINESS",@"FIRST", nil];
return items;


}

- (void)slideView:(HHSlideView *)slideView didSelectItemAtIndex:(NSInteger)index {
NSLog(@" index %li", index);

flag = index ;

if(flag == 1 || flag == 2)
{
SampleTableViewController * obj = [[SampleTableViewController alloc]init];

[obj.reloadtable reloadData];

}
}


Class B

-(void)sampleMethod
{

[self.reloadtable reloadData];

}

Answer

You need to use NSNotificationCentre for reload tablview in containerView(class B).

Add

 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(reloadTablViewWithNotification:) name:@"reloadTableView" object:nil];

-(void)reloadTablViewWithNotification:(NSNotification *)notification{
    NSLog(@"%@",[notification object]); // prints "Your object"
// here you can reload your tableview
}

// post when your need

[[NSNotificationCenter defaultCenter]postNotificationName:@"reloadTableView" object:@"Your object"];
Comments