Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
flyOfYW committed Aug 17, 2018
1 parent f5c6e18 commit fde4b7f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion YWExcel.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "YWExcel"
s.version = "0.0.1"
s.version = "0.0.2"
s.summary = "打造iOS的excel表展示控件"

# This description is used to generate tags and improve search results.
Expand Down
1 change: 0 additions & 1 deletion YWExcelView/YWExcelCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#import <UIKit/UIKit.h>

static NSString *cellScrollNotification = @"cellScrollNotification";


@interface YWExcelCell : UITableViewCell
Expand Down
15 changes: 8 additions & 7 deletions YWExcelView/YWExcelCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ @interface YWExcelCell ()
<UIScrollViewDelegate>
{
UILabel *_titleLabel;
BOOL _isNotification;
BOOL _isAllowedNotification;
CGFloat _lastOffX;
CGFloat _defalutWidth;
NSString *_notif;
Expand Down Expand Up @@ -184,20 +184,20 @@ - (void)initItemWidths:(NSArray *)itemWidths

#pragma mark - UIScrollViewDelegate
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
_isNotification = NO;//
_isAllowedNotification = NO;//
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
_isNotification = NO;
_isAllowedNotification = NO;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (!_isNotification) {//是自身才发通知去tableView以及其他的cell
if (!_isAllowedNotification) {//是自身才发通知去tableView以及其他的cell
// 发送通知
[[NSNotificationCenter defaultCenter] postNotificationName:_notif object:self userInfo:@{@"cellOffX":@(scrollView.contentOffset.x)}];
}
_isNotification = NO;
_isAllowedNotification = NO;
}

-(void)scrollMove:(NSNotification*)notification
Expand All @@ -206,13 +206,13 @@ -(void)scrollMove:(NSNotification*)notification
NSObject *obj = notification.object;
float x = [noticeInfo[@"cellOffX"] floatValue];
if (obj!=self) {
_isNotification = YES;
_isAllowedNotification = YES;
if (_lastOffX != x) {
[_rightScrollView setContentOffset:CGPointMake(x, 0) animated:NO];
}
_lastOffX = x;
}else{
_isNotification = NO;
_isAllowedNotification = NO;
}
obj = nil;

Expand All @@ -222,6 +222,7 @@ - (void)dealloc{
NSLog(@"YWExcelCell--%s",__func__);

}
//多种手势处理
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
Expand Down
6 changes: 2 additions & 4 deletions YWExcelView/YWExcelView.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,22 @@ - (instancetype)initWithFrame:(CGRect)frame
switch (style) {
case YWExcelViewStyleDefalut:
[self initStyleWithDefalut];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollMove:) name:_NotificationID object:nil];
break;
case YWExcelViewStylePlain:
[self initStyleWithDefalut];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollMove:) name:_NotificationID object:nil];
break;
case YWExcelViewStyleheadPlain:
[self initStyleWithHeadPlain];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollMove:) name:_NotificationID object:nil];
break;
case YWExcelViewStyleheadScrollView:
[self initStyleWithHeadPlain];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollMove:) name:_NotificationID object:nil];
break;

default:
break;
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollMove:) name:_NotificationID object:nil];

}
return self;
}
Expand Down

0 comments on commit fde4b7f

Please sign in to comment.