天天看点

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

继续阅读