从其他类调用时,TableView重新加载数据不起作用

时间:2016-11-23 09:29:54

标签: ios objective-c uitableview

我有两个类,class A包含容器,UISegmentControl位于class B我有一个UITableView,它嵌入了容器。 最初在加载数据时UITableView正在加载UISegmentControl我在class B中重新加载时,@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; 正在加载,因为没有进行表重新加载!

带有容器的A类

- (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];

   }
 }

}

-(void)sampleMethod
    {

 [self.reloadtable reloadData];

  }

B类

NoRecovery

1 个答案:

答案 0 :(得分:-1)

您需要在containerView(B类)中使用NSNotificationCentre重新加载tablview。

添加

 [[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
}

//在您需要时发布

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