Can't use reloadData from another class

前端 未结 7 2067
栀梦
栀梦 2021-01-15 03:56

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 <

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-15 04:21

    I think u should reload it by delegates.

    Here your ClassB.h Here u need to add your delegate

    @property (nonatomic, strong) id myDelegate;
    

    Here your ClassA.m When u are going to ClassB show his delegate t ClassA

    ClassB *goNext = [[ClassB alloc] initWithNibName:@"ClassB" bundle:nil];
    goNext.myDelegate = self; // ALL YOUR BASE ARE BELONG TO US!
    [self.navigationController pushViewController:goNext animated:YES];
    

    Next. When u want to reload your classA tableView use the code like this:

    if (myDelegate && [myDelegate respondsToSelector:@selector(reloadMyTV)]){
            [myDelegate performSelector:@selector(reloadMyTV) withObject:nil];
        }
    

    where "reloadMyTV" is method of ClassA:

    -(void) reloadMyTV {
    [myTableView reloadData];
    }
    

    Hope I remember delegates good enough ) I wrote it by memory )) Hope it will help

提交回复
热议问题