瀏覽代碼

fix change user

Marino Faggiana 7 年之前
父節點
當前提交
863ac98136
共有 1 個文件被更改,包括 16 次插入4 次删除
  1. 16 4
      iOSClient/Settings/CCManageAccount.m

+ 16 - 4
iOSClient/Settings/CCManageAccount.m

@@ -177,10 +177,21 @@
 {
     [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
     
-    if ([rowDescriptor.tag isEqualToString:@"pickerAccount"] && oldValue && newValue){
+    if ([rowDescriptor.tag isEqualToString:@"pickerAccount"] && oldValue && newValue) {
         
-        // cambiamo default account se oldvalue != newValue
-        if (![newValue isEqualToString:oldValue]) [self ChangeDefaultAccount:newValue];
+        XLFormPickerCell *pickerAccount = (XLFormPickerCell *)[[self.form formRowWithTag:@"pickerAccount"] cellForFormController:self];
+        NSString *accountNow = pickerAccount.rowDescriptor.value;
+
+        if (![newValue isEqualToString:oldValue] && ![newValue isEqualToString:@""] && ![newValue isEqualToString:appDelegate.activeAccount])
+            [self ChangeDefaultAccount:newValue];
+        
+        if ([newValue isEqualToString:@""]) {
+            
+            NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
+
+            if ([listAccount count] > 0)
+                [self ChangeDefaultAccount:listAccount[0]];
+        }
     }
 }
 
@@ -269,7 +280,8 @@
         [self deleteAccount:accountNow];
         
         NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
-        if ([listAccount count] > 0) [self ChangeDefaultAccount:listAccount[0]];
+        if ([listAccount count] > 0)
+            [self ChangeDefaultAccount:listAccount[0]];
         else {
             [self addAccountForced];
         }