Forráskód Böngészése

修复portfolio 没有全选的情况下,单独一项一项的选,选全之后select title没变

Pen Li 9 éve
szülő
commit
4f68971d87

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


+ 76 - 32
RedAnt ERP Mobile/common/Functions/portfolio/PortfolioViewController.m

@@ -23,6 +23,7 @@
 #import "DefaultAppearance.h"
 
 #define ALERT_DEL 1025
+#define checked_Count @"checkedCount"
 @interface PortfolioViewController ()
 
 @end
@@ -485,8 +486,7 @@
     //            tap.minimumPressDuration = 0.8; //定义按的时间
     [self.label_net_err addGestureRecognizer:tap];
     
-
-    
+    [self initCheckedCount];
 }
 
 -(void)manually_refresh
@@ -506,44 +506,47 @@
 - (IBAction)onSelectClick:(id)sender {
     //    self.total=0;
     
+    int count =[[self.content_data valueForKey:@"count"] intValue];
     
-    if([self.btnselect.title isEqualToString:@"Select all"])
-    {
-        int count =[[self.content_data valueForKey:@"count"] intValue];
-        for(int i=0;i<count;i++)
+    if (count) {
+        if([self.btnselect.title isEqualToString:@"Select all"])
         {
-            NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
-            [item_json setValue:@"1" forKey:@"check"];
-            
-            ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
-            cell.img_checkmark.hidden=false;
-            //            double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
             
-            [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
+            for(int i=0;i<count;i++)
+            {
+                NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
+                [item_json setValue:@"1" forKey:@"check"];
+                
+                ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
+                cell.img_checkmark.hidden=false;
+                //            double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
+                
+                [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
+                
+                
+            }
+            [self initCheckedCount];
+            [self.btnselect setTitle:@"Deselect all"];
             
             
         }
-        
-        [self.btnselect setTitle:@"Deselect all"];
-        
-        
-    }
-    else
-    {
-        int count =[[self.content_data valueForKey:@"count"] intValue];
-        for(int i=0;i<count;i++)
+        else
         {
-            NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)i]] mutableCopy];
-            [item_json setValue:@"0" forKey:@"check"];
-            
-            ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
-            cell.img_checkmark.hidden=true;
-            [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
-            
+            //        int count =[[self.content_data valueForKey:@"count"] intValue];
+            for(int i=0;i<count;i++)
+            {
+                NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)i]] mutableCopy];
+                [item_json setValue:@"0" forKey:@"check"];
+                
+                ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
+                cell.img_checkmark.hidden=true;
+                [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
+                
+            }
+            [self clearCheckedCount];
+            [self.btnselect setTitle:@"Select all"];
+            //        self.btnselect.titleLabel.text=@"Select all";
         }
-        
-        [self.btnselect setTitle:@"Select all"];
-        //        self.btnselect.titleLabel.text=@"Select all";
     }
     
 }
@@ -867,6 +870,7 @@
                 self.content_data = [cart_json mutableCopy];
                 [self.itemListTable reloadData];
                 
+                [self initCheckedCount];
                 [self.btnselect setTitle: @"Deselect all"];
                 UIApplication * app = [UIApplication sharedApplication];
                 AppDelegate *appDelegate = (AppDelegate *)[app delegate];
@@ -1171,11 +1175,16 @@
         [item_json setValue:@"0" forKey:@"check"];
         cell.img_checkmark.hidden=true;
         [self.btnselect setTitle: @"Select all"];
+        [self checkedCountRise:NO];
     }
     else
     {
         [item_json setValue:@"1" forKey:@"check"];
         cell.img_checkmark.hidden=false;
+        [self checkedCountRise:YES];
+        if ([self allChecked]) {
+            [self.btnselect setTitle: @"DeSelect all"];
+        }
     }
     [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
     
@@ -1532,4 +1541,39 @@ commitEditingStyle:(UITableViewCellEditingStyle)editingStyle  forRowAtIndexPath:
 }
 */
 
+#pragma mark - Jack
+
+- (BOOL)allChecked {
+    int checkedCount = [[self.content_data objectForKey:checked_Count] integerValue];
+    int count = [[self.content_data objectForKey:@"count"] integerValue];
+    
+    return checkedCount == count;
+}
+
+- (void)initCheckedCount {
+    NSNumber *count = [self.content_data objectForKey:@"count"];
+    if (!count) {
+        count = [NSNumber numberWithInteger:0];
+    }
+    [self.content_data setObject:count forKey:checked_Count];
+}
+
+- (void)clearCheckedCount {
+    [self.content_data setObject:[NSNumber numberWithInteger:0] forKey:checked_Count];
+}
+
+- (void)checkedCountRise:(BOOL)rise {
+    
+    int checkedCount = [[self.content_data objectForKey:checked_Count] integerValue];
+    
+    if (rise) {
+        checkedCount++;
+    } else {
+        checkedCount--;
+    }
+    
+    [self.content_data setObject:[NSNumber numberWithInteger:checkedCount] forKey:checked_Count];
+    
+}
+
 @end