父类中有一个属性navTabBar 并且重写了getter
-(YPNavTabBar *)navTabBar{
if (_navTabBar == nil) {
YPNavTabBar* navTabBar = [[YPNavTabBar alloc] init];
navTabBar.frame = CGRectMake(0, 0, self.view.width, [self navTabBarHeight]);
navTabBar.delegate = self;
navTabBar.itemTitles = self.titles;
// 更新选项条标题数据
[navTabBar updateData];
[self.view addSubview:navTabBar];
self.navTabBar = navTabBar;
}
return _navTabBar;
}
在子类中我要重写这个属性的getter的话 则需要用到 @synthesize
@synthesize navTabBar = _navTabBar;
-(YPNavTabBar *)navTabBar{
if (_navTabBar == nil) {
YPNavTabBar* navTabBar = [[YPNavTabBar alloc] init];
navTabBar.frame = CGRectMake(0, 0, self.view.width, [self navTabBarHeight]);
navTabBar.delegate = self;
navTabBar.itemTitles = self.titles;
// 更新选项条标题数据
[navTabBar updateData];
[self.view addSubview:navTabBar];
self.navTabBar = navTabBar;
}
return _navTabBar;
}
YPNavTabBar中有一个progress属性 并且重写了setter
/** 拖动比例 */
@property (nonatomic, assign) CGFloat progress;
#pragma mark - setter -
- (void)setProgress:(CGFloat)progress
{
_progress = progress;
_currentItemIndex = (int)progress;
if (_currentItemIndex > [_items count] - 1) {
return;
}
UIButton *oldBtn;
if (_currentItemIndex > 0) {
...
父类中引用到此progress属性的相关代码
// ScrollViewDidScroll中
_navTabBar.currentItemIndex = _currentIndex;
CGFloat progress = scrollView.contentOffset.x / self.view.width;
_navTabBar.progress = progress;
_navTabBar.progress = progress; 执行到这句. 在子类未重写navTabBar的getter方法的时候 会正确调用 YPNavTabBar 的 setProgress 方法. 但是在子类重写了navTabBar的getter方法后 这句就失效了
将上面的代码改为
// ScrollViewDidScroll中
self.navTabBar.currentItemIndex = _currentIndex;
CGFloat progress = scrollView.contentOffset.x / self.view.width;
self.navTabBar.progress = progress;
则问题解决 思考中...