ソースを参照

1.修改Price Setting,当Category没有子节点时,将其设置为自己的子节点。

Pen Li 8 年 前
コミット
16b5389ffa

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


+ 24 - 9
RedAnt ERP Mobile/common/Price Setting/CategoryPriceViewController.m

@@ -57,8 +57,12 @@
 }
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    NSString *sectionKey = [NSString stringWithFormat:@"category_%d",section];
-    return [[[self.categoryGivenPrice objectForKey:sectionKey] objectForKey:@"count"] integerValue];
+    NSString *sectionKey = [NSString stringWithFormat:@"category_%ld",section];
+    NSInteger rows = [[[self.categoryGivenPrice objectForKey:sectionKey] objectForKey:@"count"] integerValue];
+    if (rows == 0) {
+        rows = 1;
+    }
+    return rows;
 }
 
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@@ -68,8 +72,13 @@
     // 解析数据
     NSInteger section = indexPath.section;
     NSInteger row = indexPath.row;
-    NSDictionary *categorySection = [self.categoryGivenPrice objectForKey:[NSString stringWithFormat:@"category_%d",section]];
-    NSDictionary *categoryRow = [categorySection objectForKey:[NSString stringWithFormat:@"category_%d",row]];
+    NSDictionary *categorySection = [self.categoryGivenPrice objectForKey:[NSString stringWithFormat:@"category_%ld",section]];
+    NSDictionary *categoryRow = [categorySection objectForKey:[NSString stringWithFormat:@"category_%ld",row]];
+    
+    NSInteger rows = [[[self.categoryGivenPrice objectForKey:[NSString stringWithFormat:@"category_%ld",section]] objectForKey:@"count"] integerValue];
+    if (rows == 0) {
+        categoryRow = categorySection;
+    }
 
     cell.categoryPrice = categoryRow;
     
@@ -88,12 +97,12 @@
 
 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
     
-    NSString *sectionKey = [NSString stringWithFormat:@"category_%d",section];
+    NSString *sectionKey = [NSString stringWithFormat:@"category_%ld",section];
     
     UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 40)];
     headerView.backgroundColor = [UIColor colorWithHEX:0xEFEAE5];
     
-    UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 100, 20)];
+    UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 180, 20)];
     categoryLabel.textColor = [UIColor blackColor];
     categoryLabel.font = [UIFont systemFontOfSize:17.0f];
     categoryLabel.textAlignment = NSTextAlignmentLeft;
@@ -119,10 +128,16 @@
             
             NSInteger section = indexPath.section;
             NSInteger row = indexPath.row;
-            NSDictionary *categorySection = [[self.categoryGivenPrice objectForKey:[NSString stringWithFormat:@"category_%d",section]] mutableCopy];
-            [categorySection setValue:result forKey:[NSString stringWithFormat:@"category_%d",row]];
+            NSDictionary *categorySection = [[self.categoryGivenPrice objectForKey:[NSString stringWithFormat:@"category_%ld",section]] mutableCopy];
+            NSInteger rows = [[[self.categoryGivenPrice objectForKey:[NSString stringWithFormat:@"category_%ld",section]] objectForKey:@"count"] integerValue];
+            if (rows == 0) {
+                categorySection = result;
+            } else {
+                [categorySection setValue:result forKey:[NSString stringWithFormat:@"category_%ld",row]];
+            }
+            
             
-            [strongself.categoryGivenPrice setObject:categorySection forKey:[NSString stringWithFormat:@"category_%d",section]];
+            [strongself.categoryGivenPrice setObject:categorySection forKey:[NSString stringWithFormat:@"category_%ld",section]];
             
             dispatch_async(dispatch_get_main_queue(), ^{
                 [strongself.categoryTable reloadData];