2016-11-25 9 views
0

テーブルビューの選択された行(.checkmark)値(文字列)はsqlite DBに保存され、tableviewは同じ値で再読み込みされ、 。 、のUITableView:コードは、テーブルビューをリロードでswift sqliteから選択した行(.checkmark)の値を再ロードする方法

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

     print("selected \(arr[indexPath.row])") 

     if let cell = medTable.cellForRowAtIndexPath(indexPath) { 
      if cell.selected { 
       cell.accessoryType = .Checkmark 

      } 
     } 

     if let selectedrows = tableView.indexPathsForSelectedRows { 

      print("didDeselectRowAtIndexPath selected rows:\(selectedrows)") 

      let objRegisterModel: RegisterModel = RegisterModel() 

      medicationFor = "\(selectedrows)" 
      objRegisterModel.MedicationFor = medicationFor; 


      let splitString = objRegisterModel.MedicationFor.componentsSeparatedByString(",") 

      print("getSelectedrowsValues", splitString) 


     } 
    } 

    func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { 

     print("deselected \(arr[indexPath.row])") 

     if let cell = medTable.cellForRowAtIndexPath(indexPath) { 
      cell.accessoryType = .None 
     } 

     if let sr = medTable.indexPathsForSelectedRows { 
      print("didDeselectRowAtIndexPath selected rows:\(sr)") 
     } 
    } 

以下に示す、値が表示されているが、

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 


     let cell = medTable.dequeueReusableCellWithIdentifier(intervalCellIdentifier, forIndexPath: indexPath) as UITableViewCell 

     cell.accessoryType = .None 
     cell.textLabel?.text = arr[indexPath.row] 

     let objRegisterModel: RegisterModel = RegisterModelManager.getDBInstance().getRegisterDataByCurrentMedID(uid) 

     if objRegisterModel != "" { 

      medicationFor = objRegisterModel.MedicationFor 
     } 


     return cell 
    } 

をチェックマークしないsqliteDBに保存された値が

**[<NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1}]** 
+0

を条件に入れ、その後accessoryType

let objRegisterModel: RegisterModel = RegisterModelManager.getDBInstance().getRegisterDataByCurrentMedID(uid) if objRegisterModel != "" { medicationFor = objRegisterModel.MedicationFor } 

を設定し、前にDB、 (tableView:UITableView、numberOfRowsInSection section:Int)メソッドです。 –

+0

func tableView(tableView:UITableView、numberOfRowsInSection section:Int) - > Int { return arr.count } –

+0

そして、arr配列に格納されている値は何ですか? –

答えて

0

FUNC用のtableView(のtableViewの下に示されているスニペットdidSelectRowAtIndexPath indexPath:NSIndexPath){ let cellN:UITableViewCell = UITableViewCell(); せた場合にisChecked ==真{ cellN.accessoryType = UITableViewCellAccessoryType.Checkmark }他{ cellN.accessoryType = UITableViewCellAccessoryType.None } 戻りセル }

あなたが表示するようにcellForRowAtIndexPathデリゲートメソッドで状態を確認する必要が

/チェックマークを隠す。

0

あなたは、これはチェックマークは、選択に示され、選択解除に隠されていることを確認しますfunc tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath)

cell.accessoryType = .Nonecell.accessoryType = .Checkmarkを追加しました。あなたがチェックマークを表示する必要がある場合は

しかし、テーブルビューのリロードの場合には、データソースメソッドfunc tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellが呼び出されたが、そこにあなただけcell.accessoryType = .None'

を追加した適切に私の理解からからデータを読み込むコードスニペット、下に呼び出します私達にあなたのtableViewを表示

応じ
if (informationShownSelectedinDB) { 
    cell.accessoryType = .Checkmark 
} else { 
    cell.accessoryType = .None 
} 
+0

ありがとう.. @ DILi、@Harsh Shah&El Tomatoすぐに結果を確認して掲載します –

関連する問題