2017-02-17 31 views

回答

0

我用觀察者解決了它。

- (instancetype)initWithBridge:(RCTBridge *)bridge { 
    [self addObserver:self forKeyPath:@"self.numRows" options:NSKeyValueObservingOptionNew context:nil]; 
    return self; 
} 

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 
    [self.tableView reloadData]; 
} 
4

我不認爲KVO是一個很好的解決方案。

您可以只重寫制定者財產numRows行:

- (void)setNumRows:(NSInteger)numRows { 
    _numRows = numRows; 
    [self.tableView reloadData]; 
} 

或者你可以使用RCT_CUSTOM_VIEW_PROPERTY:

RCT_CUSTOM_VIEW_PROPERTY(numRows, NSInteger, RNNativeListview) { 
    view.numRows = [RCTConvert NSInteger:json]; 
    [view.tableView reloadData]; 
} 
相關問題