Can we pass a parameter to view did load or view will appear of other class from a class

后端 未结 4 1325
悲&欢浪女
悲&欢浪女 2021-01-27 09:54

Sorry if it is not a standard question, but now your solutions can help me out. In my app, I have two classes: ClassA and ClassB. ClassB

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-27 10:33

    I'd recommend you write a setter method for your query. Once Class B is instantiated you can call the method any time to update the data set and the table view.

    You'll need to adjust the parameters to handle whatever form of representation you'll be using for your query.

    ClassB.h

    @interface ClassB : UITableViewController {
    
    }
    
    @property (nonatomic, copy) NSString *query;
    

    ClassB.m

    // method declared in ClassB
    
    @implementation 
    
    @synthesize query;
    
    // other methods here ...
    
    - (void)setQuery:(NSString *)newQuery
    {   
        // query is an instance variable declared in your .h
        [newQuery retain];
        [query release];
        query = newQuery;
    
        // perform your new data fetch with the supplied query
    
        [self.tableView reload];
    }
    
    @end
    

    ClassA.m

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        classB = [[ClassB alloc] initWithNibName:@"ClassB" bundle:nil];
        [classB setQuery:@"your query string here"];
    }
    

提交回复
热议问题