Quellcode durchsuchen

20170220

Fix homepage high memory usage and potential force crash.
Ray Zhang vor 9 Jahren
Ursprung
Commit
d2e31c21d4

BIN
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/Ray.xcuserdatad/UserInterfaceState.xcuserstate


Datei-Diff unterdrückt, da er zu groß ist
+ 5 - 1045
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/Ray.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist


+ 11 - 0
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/Ray.xcuserdatad/xcdebugger/Expressions.xcexplist

@@ -26,6 +26,14 @@
             </PersistentString>
          </PersistentStrings>
       </ContextState>
+      <ContextState
+         contextName = "-[CycleScrollView reset]:CycleScrollView.m">
+         <PersistentStrings>
+            <PersistentString
+               value = "self.subviews">
+            </PersistentString>
+         </PersistentStrings>
+      </ContextState>
       <ContextState
          contextName = "-[NSData(LowLevelCommonCryptor) dataEncryptedUsingAlgorithm:key:initializationVector:options:error:]:NSData+CommonCrypto.m">
       </ContextState>
@@ -54,6 +62,9 @@
             </PersistentString>
          </PersistentStrings>
       </ContextState>
+      <ContextState
+         contextName = "-[HomeViewController viewDidDisappear:]:HomeViewController.m">
+      </ContextState>
       <ContextState
          contextName = "-[TableDrawable Draw:dataSource:ParentRect:startX:startY:flipHeight:range:]:TableDrawable.m">
       </ContextState>

+ 6 - 5
RedAnt ERP Mobile/common/AutoScrollImage/CycleScrollView.h

@@ -20,7 +20,7 @@
  *  @return instance
  */
 - (id)initWithFrame:(CGRect)frame animationDuration:(NSTimeInterval)animationDuration;
--(void) animationDuration:(NSTimeInterval)animationDuration;
+//-(void) animationDuration:(NSTimeInterval)animationDuration;
 -(void) reset;
 -(void) addPage:(UIView*) page;
 @property (strong,nonatomic) NSMutableArray* arr_Pages;
@@ -28,14 +28,15 @@
 /**
  数据源:获取总的page个数
  **/
-@property (nonatomic , copy) NSInteger (^totalPagesCount)(void);
+//@property (nonatomic , copy) NSInteger (^totalPagesCount)(void);
 /**
  数据源:获取第pageIndex个位置的contentView
  **/
-@property (nonatomic , copy) UIView *(^fetchContentViewAtIndex)(NSInteger pageIndex);
+//@property (nonatomic , copy) UIView *(^fetchContentViewAtIndex)(NSInteger pageIndex);
 /**
  当点击的时候,执行的block
  **/
 @property (nonatomic , copy) void (^TapActionBlock)(NSInteger pageIndex);
-
-@end
+- (void)setTotalPagesCount;
+-(void) stopTimmer;
+@end

+ 90 - 31
RedAnt ERP Mobile/common/AutoScrollImage/CycleScrollView.m

@@ -8,6 +8,8 @@
 
 #import "CycleScrollView.h"
 #import "NSTimer+Addition.h"
+#import "SliderPage.h"
+#import "HWWeakTimer.h"
 
 @interface CycleScrollView () <UIScrollViewDelegate>
 
@@ -16,28 +18,54 @@
 @property (nonatomic , strong) NSMutableArray *contentViews;
 @property (nonatomic , strong) UIScrollView *scrollView;
 
-@property (nonatomic , strong) NSTimer *animationTimer;
+@property (nonatomic , weak) NSTimer *animationTimer;
 @property (nonatomic , assign) NSTimeInterval animationDuration;
 @property (nonatomic , strong) UIPageControl *pageControl;
 @end
 
 @implementation CycleScrollView
-
+-(void) dealloc
+{
+        [self.animationTimer invalidate];
+    NSLog(@"CycleScrollView dealloc");
+    
+    
+}
+-(void) stopTimmer
+{
+//    return;
+    [self.animationTimer invalidate];
+    
+//    [[NSNotificationCenter defaultCenter] removeObserver:self name:CYCLESCROLL_STOPTIMMER object:nil];
+}
 -(void) animationDuration:(NSTimeInterval)animationDuration
 {
+   // return;
+    
     if (animationDuration > 0.0) {
-        self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:(self.animationDuration = animationDuration)
-                                                               target:self
-                                                             selector:@selector(animationTimerDidFired:)
-                                                             userInfo:nil
-                                                              repeats:YES];
+//        self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:(self.animationDuration = animationDuration)
+//                                                               target:self
+//                                                             selector:@selector(animationTimerDidFired:)
+//                                                             userInfo:nil
+//                                                              repeats:YES];
+        
+                self.animationTimer = [HWWeakTimer scheduledTimerWithTimeInterval:(self.animationDuration = animationDuration)
+                                                                       target:self
+                                                                     selector:@selector(animationTimerDidFired:)
+                                                                     userInfo:nil
+                                                                      repeats:YES];
+        
+//         self.animationTimer =[HWWeakTimer scheduledTimerWithTimeInterval:3.0f block:^(id userInfo) {
+//            NSLog(@"%@", userInfo);
+//        } userInfo:@"Fire" repeats:YES];
         [self.animationTimer pauseTimer];
     }
 }
 
-- (void)setTotalPagesCount:(NSInteger (^)(void))totalPagesCount
+- (void)setTotalPagesCount
 {
-    _totalPageCount = totalPagesCount();
+    
+    _totalPageCount = self.arr_Pages.count;
     if (_totalPageCount > 0) {
         [self configContentViews];
         [self.animationTimer resumeTimerAfterTimeInterval:self.animationDuration];
@@ -54,7 +82,7 @@
     self.arr_Pages =[@[] mutableCopy];
        // Initialization code
     self.autoresizesSubviews = YES;
-    self.scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
+//    self.scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
     self.scrollView.autoresizingMask = 0xFF;
     self.scrollView.contentMode = UIViewContentModeCenter;
     self.scrollView.contentSize = CGSizeMake(3 * CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame));
@@ -64,15 +92,15 @@
     self.scrollView.delegate = self;
     self.scrollView.contentOffset = CGPointMake(CGRectGetWidth(self.scrollView.frame), 0);
     self.scrollView.pagingEnabled = YES;
-    [self addSubview:self.scrollView];
+//    [self addSubview:self.scrollView];
     
-    CGRect pageFrame =self.bounds;
-    pageFrame.origin.y = self.frame.size.height -16-20;
-    pageFrame.size.height = 20;
+//    CGRect pageFrame =self.bounds;
+//    pageFrame.origin.y = self.frame.size.height -16-20;
+//    pageFrame.size.height = 20;
 //    pageFrame
-    self.pageControl = [[UIPageControl alloc] initWithFrame:pageFrame];//CGRectMake(0, self.frame.size.height -16-10, 320, 10)];
+//    self.pageControl = [[UIPageControl alloc] initWithFrame:pageFrame];//CGRectMake(0, self.frame.size.height -16-10, 320, 10)];
     self.pageControl.userInteractionEnabled = NO;
-    [self addSubview:self.pageControl];
+//    [self addSubview:self.pageControl];
   //  int count =self.totalPageCount;
 //    self.pageControl.backgroundColor = [UIColor purpleColor];
     self.pageControl.numberOfPages = self.totalPageCount;
@@ -91,14 +119,16 @@
 - (id)initWithFrame:(CGRect)frame animationDuration:(NSTimeInterval)animationDuration
 {
     self = [self initWithFrame:frame];
-    if (animationDuration > 0.0) {
-        self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:(self.animationDuration = animationDuration)
-                                                               target:self
-                                                             selector:@selector(animationTimerDidFired:)
-                                                             userInfo:nil
-                                                              repeats:YES];
-        [self.animationTimer pauseTimer];
-    }
+//    if (animationDuration > 0.0) {
+//        self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:(self.animationDuration = animationDuration)
+//                                                               target:self
+//                                                             selector:@selector(animationTimerDidFired:)
+//                                                             userInfo:nil
+//                                                              repeats:YES];
+//        [self.animationTimer pauseTimer];
+//    }
+    
+    [self animationDuration:animationDuration];
     return self;
 }
 
@@ -117,6 +147,16 @@
         self.scrollView.pagingEnabled = YES;
         [self addSubview:self.scrollView];
         self.currentPageIndex = 0;
+        
+        
+        CGRect pageFrame =self.bounds;
+        pageFrame.origin.y = self.frame.size.height -16-20;
+        pageFrame.size.height = 20;
+        self.pageControl = [[UIPageControl alloc] initWithFrame:pageFrame];
+        [self addSubview:self.pageControl];
+        
+        
+//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopTimmer) name:CYCLESCROLL_STOPTIMMER object:nil];
     }
     return self;
 }
@@ -154,17 +194,36 @@
     }
     [self.contentViews removeAllObjects];
     
-    if (self.fetchContentViewAtIndex) {
-        [self.contentViews addObject:self.fetchContentViewAtIndex(previousPageIndex)];
-        [self.contentViews addObject:self.fetchContentViewAtIndex(_currentPageIndex)];
+//    if (self.fetchContentViewAtIndex)
+    {
         
         
-        UIView* currentView =self.fetchContentViewAtIndex(_currentPageIndex);
-        currentView.gestureRecognizers= nil;
+        
+        SliderPage* previousPage =self.arr_Pages[previousPageIndex];
+        [previousPage loadImage];
+        
+        
+
+     
+        
+        [self.contentViews addObject:previousPage];
+        
+        
+        SliderPage* currentPage =self.arr_Pages[_currentPageIndex];
+        [currentPage loadImage];
+        [self.contentViews addObject:currentPage];
+        
+        
+//        UIView* currentView =self.fetchContentViewAtIndex(_currentPageIndex);
+        currentPage.gestureRecognizers= nil;
         UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contentViewTapAction:)];
-        [self.fetchContentViewAtIndex(_currentPageIndex) addGestureRecognizer:tapGesture];
+        [currentPage addGestureRecognizer:tapGesture];
+        
+        
+        SliderPage* rearPage =self.arr_Pages[rearPageIndex];
+        [rearPage loadImage];
         
-        [self.contentViews addObject:self.fetchContentViewAtIndex(rearPageIndex)];
+        [self.contentViews addObject:rearPage];
     }
 }
 

+ 14 - 0
RedAnt ERP Mobile/common/Functions/MainViewController.m

@@ -1043,6 +1043,7 @@
     
     
     toController.view.autoresizingMask =     UIViewAutoresizingFlexibleHeight  |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
+    NSLog(@"MAIN VIEWCONTROLLER CHILD COUNT %lu",(unsigned long)self.childViewControllers.count);
     [self addChildViewController:toController];                                     //
     [fromController willMoveToParentViewController:nil];                            //
     
@@ -1059,6 +1060,13 @@
                                 self.current_VC = toController;
                                 
                                 
+                                    if([fromController isKindOfClass:[HomeViewController class]])
+                                    {
+                                       // [[NSNotificationCenter defaultCenter] postNotificationName:CYCLESCROLL_STOPTIMMER object:nil];
+                                       // self.homeViewController = nil;
+                                        
+                                    }
+                                
                                 
                                 
                             }];
@@ -1184,6 +1192,12 @@
 {
     if([self.current_VC isKindOfClass:[HomeViewController class]])
         return;
+    
+    if(self.homeViewController == nil)
+    {
+        self.homeViewController =[ self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
+        self.homeViewController.view.frame = self.container.bounds;
+    }
     [self flipFromViewController:self.current_VC toViewController:self.homeViewController withDirection:UIViewAnimationOptionTransitionCrossDissolve];
     
 }

+ 4 - 4
RedAnt ERP Mobile/common/Functions/home/HomeTableViewCellSlide.m

@@ -15,10 +15,10 @@
     
     
    // DebugLog(NSStringFromCGRect(self.frame));
-    self.imgScroll =  [[CycleScrollView alloc] initWithFrame:self.frame  animationDuration:5];
-    self.imgScroll.autoresizingMask =     UIViewAutoresizingFlexibleHeight  |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
-
-    [self.contentView addSubview:self.imgScroll];
+//    self.imgScroll =  [[CycleScrollView alloc] initWithFrame:self.frame  animationDuration:5];
+//    self.imgScroll.autoresizingMask =     UIViewAutoresizingFlexibleHeight  |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
+//
+//    [self.contentView addSubview:self.imgScroll];
 }
 
 - (void)setSelected:(BOOL)selected animated:(BOOL)animated {

+ 1 - 0
RedAnt ERP Mobile/common/Functions/home/HomeViewController.h

@@ -24,6 +24,7 @@
 @property (strong, nonatomic) IBOutlet UITableView *homeTable;
 //@property (strong,nonatomic) NSMutableArray * sideMenuItems;
 @property (strong,nonatomic) NSDictionary* content;
+@property (strong,nonatomic) NSDictionary* bak_content;
 @property (strong, nonatomic) id expanded;
 //@property (strong,nonatomic) NSDictionary*
 //@property (strong,nonatomic) NSMutableArray * arr_topicView;

+ 86 - 28
RedAnt ERP Mobile/common/Functions/home/HomeViewController.m

@@ -14,6 +14,8 @@
 #import "MainViewController.h"
 #import "HomeTableViewCellButtonBanner.h"
 #import "WebViewController.h"
+#import "ImageUtils.h"
+#import "HomeTableViewCellSlide.h"
 
 //#import "MainViewController.h"
 
@@ -22,6 +24,10 @@
 @end
 
 @implementation HomeViewController
+-(void) dealloc
+{
+    NSLog(@"HOME VIEWCONTROLLER DEALLOC");
+}
 -(void) refresh_on_login
 {
     // do not refresh on login;
@@ -46,6 +52,17 @@
 {
     [super viewWillAppear:animated];
     [[self navigationController] setNavigationBarHidden:YES animated:NO];
+//    self.content = self.bak_content;
+//    [self reload_container_getdata:false];
+}
+-(void) viewWillDisappear:(BOOL)animated
+{
+//                                            [[NSNotificationCenter defaultCenter] postNotificationName:CYCLESCROLL_STOPTIMMER object:nil];
+//    self.bak_content = self.content;
+//    self.content= nil;
+////    self.homeTable re
+//    [self.homeTable reloadData];
+    
 }
 -(void)manually_refresh
 {
@@ -250,7 +267,15 @@
     //    // [self.carouselController updateFrame:CGRectMake(0, 0, self.view.frame.size.width, 400)];
 }
 #pragma mark - Table view data source
-- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
+- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
+{
+    if([cell isKindOfClass:[HomeTableViewCellSlide class]])
+    {
+        HomeTableViewCellSlide* slidecell=(HomeTableViewCellSlide*)cell;
+        [slidecell.imgScroll stopTimmer];
+    }
+}
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
 {
   //  UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
     //    if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
@@ -359,27 +384,41 @@
         NSString *CellIdentifier = @"HomeTableViewCellSlide";
         cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
         
-        // return cell;
+        HomeTableViewCellSlide* slidecell = (HomeTableViewCellSlide*)cell;
         
-        for(UIView* v in cell.contentView.subviews)
-        {
-            [v removeFromSuperview];
-            
-        }
+        [slidecell.imgScroll stopTimmer];
+        [slidecell.imgScroll removeFromSuperview];
+//        for(UIView* v in cell.contentView.subviews)
+//        {
+//            [v removeFromSuperview];
+//            
+//        }
         
         int i_width = 981;
         int i_height = 512;
         
         int ui_height = (tableView.frame.size.width * i_height)/i_width;
         
+//        HomeTableViewCellSlide* slidecell = (HomeTableViewCellSlide*)cell;
+        //        imgScroll.tag = 1394;
+        //
+        //
+        //        for (UIView *v in cell.contentView.subviews) {
+        //            if(v.tag==1394)
+        //                [v removeFromSuperview];
+        //        }
+        
         
         
         CycleScrollView *imgScroll =  [[CycleScrollView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, ui_height)  animationDuration:5];
+        
         imgScroll.autoresizingMask =     UIViewAutoresizingFlexibleHeight  |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
         int slide_item_count = [[view_json valueForKey:@"count"] intValue];
+        
         //imgScroll.frame =CGRectMake(0, 5, width, 300);
         [imgScroll reset];
-        [imgScroll animationDuration:5];
+        
+//        [imgScroll animationDuration:5];
         imgScroll.backgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:0.1];
         
         for(int i = 0;i<slide_item_count;i++)
@@ -405,26 +444,29 @@
         }
         
         
+//        return cell;
+//        return cell;
         //Capturing strongly  warring;
-        __block CycleScrollView *brimgScroll= imgScroll;
+//        __block CycleScrollView *brimgScroll= imgScroll;
         
-        imgScroll.fetchContentViewAtIndex = ^UIView *(NSInteger pageIndex){
-            
-            
-            
-            SliderPage* page =brimgScroll.arr_Pages[pageIndex];
-            [page loadImage];
-            
-            
-            
-            return page ;
-            
-            //                UIImageView * v= viewsArray[pageIndex];
-            //                return viewsArray[pageIndex];
-        };
-        imgScroll.totalPagesCount = ^NSInteger(void){
-            return brimgScroll.arr_Pages.count; //viewsArray.count;
-        };
+//        imgScroll.fetchContentViewAtIndex = ^UIView *(NSInteger pageIndex){
+//            
+//            
+//            
+//            SliderPage* page =brimgScroll.arr_Pages[pageIndex];
+//            [page loadImage];
+//            
+//            
+//            
+//            return page ;
+//            
+//            //                UIImageView * v= viewsArray[pageIndex];
+//            //                return viewsArray[pageIndex];
+//        };
+//        imgScroll.totalPagesCount = ^NSInteger(void){
+//            return brimgScroll.arr_Pages.count; //viewsArray.count;
+//        };
+        [imgScroll setTotalPagesCount];
         imgScroll.TapActionBlock = ^(NSInteger pageIndex){
             DebugLog(@"点击了第%ld个",(long)pageIndex);
             //            NSDictionary * slide_itemjson =[view_json objectForKey:[NSString stringWithFormat:@"item_%d",pageIndex] ];
@@ -442,6 +484,22 @@
             //            [self.navigationController pushViewController:dvc animated:true];
         };
         
+//        HomeTableViewCellSlide* slidecell = (HomeTableViewCellSlide*)cell;
+        
+//        [slidecell.imgScroll stopTimmer];
+//        [slidecell.imgScroll removeFromSuperview];
+        
+        
+//        imgScroll.tag = 1394;
+//        
+//        
+//        for (UIView *v in cell.contentView.subviews) {
+//            if(v.tag==1394)
+//                [v removeFromSuperview];
+//        }
+//
+        slidecell.imgScroll = imgScroll;
+//        return cell;
         [cell.contentView addSubview:imgScroll];
         
         
@@ -506,7 +564,7 @@
         HomeTableViewCellBanner * bannercell=cell;
         NSString* img_url =[view_json valueForKeyPath:@"img"];
         NSString* file_name=[img_url lastPathComponent];
-        NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
+        NSData* img_data=[ImageUtils load_cached_img:file_name loadFrom:img_url size:bannercell.BannerImageView.frame.size allow_enlarge:false];
         if(img_data!=nil)
         {
             
@@ -592,7 +650,7 @@
             [cell.contentView addSubview:btn_item];
             NSString* img_url =[item_json valueForKeyPath:@"img"];
             NSString* file_name=[img_url lastPathComponent];
-            NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
+            NSData* img_data=[ImageUtils load_cached_img:file_name loadFrom:img_url size:btn_item.frame.size allow_enlarge:false];
             if(img_data!=nil)
             {
                 

+ 1 - 0
RedAnt ERP Mobile/common/ImageUtils.h

@@ -13,4 +13,5 @@
 + (CGRect)rectAlign:(CGRect )parent rect:(CGRect)rect hAlign:(NSString*)hAlign vAlign:(NSString*)vAlign;
 + (NSData*) load_cached_img:(NSString*) filename loadFrom:(NSString*) path;
 + (NSData*) load_img:(NSString*) filename ;
++ (NSData*) load_cached_img:(NSString*) filename loadFrom:(NSString*) path size:(CGSize)size allow_enlarge:(bool)allow_enlarge;
 @end

+ 67 - 32
RedAnt ERP Mobile/common/ImageUtils.m

@@ -10,6 +10,57 @@
 #import "AppDelegate.h"
 
 @implementation ImageUtils
+
+
++ (NSData*) load_cached_img:(NSString*) filename loadFrom:(NSString*) path size:(CGSize)size allow_enlarge:(bool)allow_enlarge
+{
+    
+    NSData* data=[self load_cached_img:filename loadFrom:path];
+    
+    return data; 
+    UIImage* img = [UIImage imageWithData:data];
+    if(!allow_enlarge&&(size.width>img.size.width|| size.height>img.size.height))
+        return data;
+            
+            
+//    CGRect rect = [self scaleToSize:CGRectMake(0, 0, img.size.width, img.size.height) to:size];
+    UIImage* scaledimg=[self scaleImageToSize:img size:size];
+
+    NSData *scaledData = UIImagePNGRepresentation(scaledimg);
+    return scaledData;
+}
++ (NSData*) load_cached_img:(NSString*) filename loadFrom:(NSString*) path
+{
+    if(path.length==0)
+        return nil;
+    
+    path=[path stringByReplacingOccurrencesOfString:@"https://" withString:@""];
+    path=[path stringByReplacingOccurrencesOfString:@"http://" withString:@""];
+    //    path=[path stringByReplacingOccurrencesOfString:filename withString:@""];
+    
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    
+    if(appDelegate.bEnable_Cache==false)
+        return nil;
+    
+    
+    NSData* data = nil;
+    
+    
+    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+    NSString *cachefolder = [paths objectAtIndex:0];
+    NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
+    NSString *filePath = [img_cache stringByAppendingPathComponent:path];
+    
+    NSFileManager* fileManager = [NSFileManager defaultManager];
+    if(  [fileManager fileExistsAtPath:filePath ])
+    {
+        data = [NSData dataWithContentsOfFile: filePath];
+    }
+    return data;
+    
+}
+
 + (CGRect)scaleToSize:(CGRect )from to:(CGSize)to
 {
     if(from.size.width/from.size.height>to.width/to.height)
@@ -35,6 +86,22 @@
     //    return scaledImage;
 }
 
++ (UIImage *)scaleImageToSize:(UIImage *)img size:(CGSize)size{
+    // 创建一个bitmap的context
+    // 并把它设置成为当前正在使用的context
+    UIGraphicsBeginImageContext(size);
+    // 绘制改变大小的图片
+    [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
+    // 从当前context中创建一个改变大小后的图片
+    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
+    // 使当前的context出堆栈
+    UIGraphicsEndImageContext();
+    // 返回新的改变大小后的图片
+    
+    //   NSData  *imageData=UIImageJPEGRepresentation(scaledImage, 1.f);
+    return scaledImage;
+}
+
 + (CGRect)rectAlign:(CGRect )parent rect:(CGRect)rect hAlign:(NSString*)hAlign vAlign:(NSString*)vAlign
 {
     //    double cx=parent.origin.x+parent.size.width/2;
@@ -62,39 +129,7 @@
     return rect;
     
 }
-+ (NSData*) load_cached_img:(NSString*) filename loadFrom:(NSString*) path
-{
-    if(path.length==0)
-        return nil;
-    
-    path=[path stringByReplacingOccurrencesOfString:@"https://" withString:@""];
-    path=[path stringByReplacingOccurrencesOfString:@"http://" withString:@""];
-    //    path=[path stringByReplacingOccurrencesOfString:filename withString:@""];
-    
-    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-    
-    if(appDelegate.bEnable_Cache==false)
-        return nil;
-    
-    
-    NSData* data = nil;
-    
-    
-    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
-    NSString *cachefolder = [paths objectAtIndex:0];
-    NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
-    NSString *filePath = [img_cache stringByAppendingPathComponent:path];
-    
-    NSFileManager* fileManager = [NSFileManager defaultManager];
-    if(  [fileManager fileExistsAtPath:filePath ])
-    {
-        data = [NSData dataWithContentsOfFile: filePath];
-    }
-    
 
-    return data;
-    
-}
 + (NSData*) load_img:(NSString*) filename
 {
     if(filename.length==0)

+ 1 - 1
RedAnt ERP Mobile/common/const.h

@@ -30,7 +30,7 @@
 #define COLOR(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]
 
 #define DBNAME    @"iSales.db"
-
+#define CYCLESCROLL_STOPTIMMER  @"CycleScroll stop timer"
 #define URL_REMOTE 1
 #define URL_LOCAL 0
 #define URL_NONE 2

+ 6 - 0
RedAnt ERP Mobile/iSales-NPD.xcodeproj/project.pbxproj

@@ -86,6 +86,7 @@
 		7142E87F1DC300690077EFA2 /* DejaVuSans.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 7142E87D1DC300010077EFA2 /* DejaVuSans.ttf */; };
 		714B1F401C7BF74100539193 /* OrderDetailSignatureCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 714B1F3F1C7BF74100539193 /* OrderDetailSignatureCell.m */; };
 		715001FF1D114D9100F5927F /* BundleDetailButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 715001FE1D114D9100F5927F /* BundleDetailButton.m */; };
+		7155444F1E56E0B500A808AA /* HWWeakTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 7155444E1E56E0B500A808AA /* HWWeakTimer.m */; };
 		715671331E10A0EF006324A0 /* RectDrawable.m in Sources */ = {isa = PBXBuildFile; fileRef = 715671321E10A0EF006324A0 /* RectDrawable.m */; };
 		715850461CF6F0E500856B20 /* DefaultAppearance.m in Sources */ = {isa = PBXBuildFile; fileRef = 715850451CF6F0E500856B20 /* DefaultAppearance.m */; };
 		715F30BD1DAB37EB00490EED /* OfflineUnlockViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 715F30BC1DAB37EB00490EED /* OfflineUnlockViewController.m */; };
@@ -382,6 +383,8 @@
 		714B1F3F1C7BF74100539193 /* OrderDetailSignatureCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OrderDetailSignatureCell.m; path = common/Functions/order/OrderDetailSignatureCell.m; sourceTree = SOURCE_ROOT; };
 		715001FD1D114D9100F5927F /* BundleDetailButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BundleDetailButton.h; path = common/Functions/BundleDetailButton.h; sourceTree = SOURCE_ROOT; };
 		715001FE1D114D9100F5927F /* BundleDetailButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BundleDetailButton.m; path = common/Functions/BundleDetailButton.m; sourceTree = SOURCE_ROOT; };
+		7155444D1E56E0B500A808AA /* HWWeakTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HWWeakTimer.h; sourceTree = "<group>"; };
+		7155444E1E56E0B500A808AA /* HWWeakTimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HWWeakTimer.m; sourceTree = "<group>"; };
 		715671311E10A0EF006324A0 /* RectDrawable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RectDrawable.h; path = common/pdfCreator/RectDrawable.h; sourceTree = SOURCE_ROOT; };
 		715671321E10A0EF006324A0 /* RectDrawable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RectDrawable.m; path = common/pdfCreator/RectDrawable.m; sourceTree = SOURCE_ROOT; };
 		715850441CF6F0E500856B20 /* DefaultAppearance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DefaultAppearance.h; path = common/Functions/DefaultAppearance.h; sourceTree = SOURCE_ROOT; };
@@ -1070,6 +1073,8 @@
 		716387C71953CDB4006E65E6 /* utils */ = {
 			isa = PBXGroup;
 			children = (
+				7155444D1E56E0B500A808AA /* HWWeakTimer.h */,
+				7155444E1E56E0B500A808AA /* HWWeakTimer.m */,
 				4289809B1E24B526005F1BD8 /* JKTimer */,
 				4289805A1E249375005F1BD8 /* UIColor+HEX */,
 				4289803C1E249339005F1BD8 /* JKLock */,
@@ -1666,6 +1671,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				7155444F1E56E0B500A808AA /* HWWeakTimer.m in Sources */,
 				7141DD531C57459B00F7DF59 /* qrspec.c in Sources */,
 				71BF07081D2F3D2800981938 /* SyncControlPanelViewController.m in Sources */,
 				4289802D1E2492D2005F1BD8 /* PriceSettingViewController.m in Sources */,

+ 40 - 0
RedAnt ERP Mobile/iSales-NPD/HWWeakTimer.h

@@ -0,0 +1,40 @@
+// The MIT License (MIT)
+//
+// Copyright (c) 2015  ( https://github.com/callmewhy )
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+
+#import <Foundation/Foundation.h>
+
+typedef void (^HWTimerHandler)(id userInfo);
+
+@interface HWWeakTimer : NSObject
+
++ (NSTimer *) scheduledTimerWithTimeInterval:(NSTimeInterval)interval
+                                      target:(id)aTarget
+                                    selector:(SEL)aSelector
+                                    userInfo:(id)userInfo
+                                     repeats:(BOOL)repeats;
+
++ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)interval
+                                      block:(HWTimerHandler)block
+                                   userInfo:(id)userInfo
+                                    repeats:(BOOL)repeats;
+
+@end

+ 93 - 0
RedAnt ERP Mobile/iSales-NPD/HWWeakTimer.m

@@ -0,0 +1,93 @@
+// The MIT License (MIT)
+//
+// Copyright (c) 2015  ( https://github.com/callmewhy )
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+
+#import "HWWeakTimer.h"
+
+@interface HWWeakTimerTarget : NSObject
+
+@property (nonatomic, weak) id target;
+@property (nonatomic, assign) SEL selector;
+@property (nonatomic, weak) NSTimer* timer;
+
+@end
+
+@implementation HWWeakTimerTarget
+
+- (void) fire:(NSTimer *)timer {
+    if(self.target) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
+        [self.target performSelector:self.selector withObject:timer.userInfo afterDelay:0.0f];
+#pragma clang diagnostic pop
+    } else {
+        [self.timer invalidate];
+    }
+}
+
+@end
+
+@implementation HWWeakTimer
+
++ (NSTimer *) scheduledTimerWithTimeInterval:(NSTimeInterval)interval
+                                      target:(id)aTarget
+                                    selector:(SEL)aSelector
+                                    userInfo:(id)userInfo
+                                     repeats:(BOOL)repeats {
+    HWWeakTimerTarget* timerTarget = [[HWWeakTimerTarget alloc] init];
+    timerTarget.target = aTarget;
+    timerTarget.selector = aSelector;
+    timerTarget.timer = [NSTimer scheduledTimerWithTimeInterval:interval
+                                                         target:timerTarget
+                                                       selector:@selector(fire:)
+                                                       userInfo:userInfo
+                                                        repeats:repeats];
+    return timerTarget.timer;
+}
+
++ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)interval
+                                      block:(HWTimerHandler)block
+                                   userInfo:(id)userInfo
+                                    repeats:(BOOL)repeats {
+    NSMutableArray *userInfoArray = [NSMutableArray arrayWithObject:[block copy]];
+    if (userInfo != nil) {
+        [userInfoArray addObject:userInfo];
+    }
+    return [self scheduledTimerWithTimeInterval:interval
+                                         target:self
+                                       selector:@selector(_timerBlockInvoke:)
+                                       userInfo:[userInfoArray copy]
+                                        repeats:repeats];
+}
+
++ (void)_timerBlockInvoke:(NSArray*)userInfo {
+    HWTimerHandler block = userInfo[0];
+    id info = nil;
+    if (userInfo.count == 2) {
+        info = userInfo[1];
+    }
+    // or `!block ?: block();` @sunnyxx
+    if (block) {
+        block(info);
+    }
+}
+
+@end

+ 3 - 1
RedAnt ERP Mobile/iSales-NPD/config.h

@@ -10,7 +10,9 @@
 #define RedAnt_ERP_Mobile_config_h
 #define BUILD_NPD
 
-//#define test_server
+
+#define test_server
+
 #define exception_switch 1
 #define notifyMe_switch 1
 

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.