天天看點

RN中RCTScrollView中屬性重名

在更新到Xcode8之後,RN中的RCTScrollView中refreshControl屬性的setter方法出錯,

代碼如下:

- (void)setRefreshControl:(RCTRefreshControl *)refreshControl
{
 if (_refreshControl) {
  [_refreshControl removeFromSuperview];
 }
 _refreshControl = refreshControl;
 [self addSubview:_refreshControl];
}
           

錯誤如下:

RN中RCTScrollView中屬性重名

誤打誤撞通過添加

@synthesize refreshControl = _refreshControl;
           

可以使用了,但不明就裡。

通過多人考究,終于發現是因為和系統API中的屬性重名了。由于這個自定義scrollview繼承了UIScrollview。而UIScrollView中也有這個屬性:

@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(_0) __TVOS_PROHIBITED;
           

覆寫父類的屬性并做一些修改的時候,編譯器就不會自動生成@synthesize property = _property。這是需要手動添加上@synthesize,在子類就能合成這個屬性的成員變量了。

參考:http://m.blog.csdn.net/article/details?id=50475608

繼續閱讀