私はいくつかのセルのセルを持つTableViewを持っており、各セルに3つのラベルがあります。選択したセル(TableView)からデータを取得
は、どのように私はここで私は実際に変数「リミット」は、後にゼロになることを別のポストに求めてきました完全なコード ある
let indexPath = self.tableView.indexPathForSelectedRow
indexPath
で別の変数にすべての3 label.textを保存することができます。事を観察する。 セルから直接データを取得できるかどうかを考えています。import UIKit
import Firebase
import FirebaseDatabase
struct limitStruct{
var name : String!
var today : String!
var limit : String!
}
class CalcViewController: UITableViewController {
var limits = [limitStruct]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
navigationController?.navigationBar.barTintColor = UIColor.black
self.title = "Calculation"
navigationController!.navigationBar.titleTextAttributes =
[NSForegroundColorAttributeName: UIColor.white]
let databaseReference = FIRDatabase.database().reference()
databaseReference.child("Limit").queryOrderedByKey().observe(.childAdded, with: {
snapshot in
var snapshotValue = snapshot.value as? NSDictionary
let name = snapshotValue!["name"] as? String
snapshotValue = snapshot.value as? NSDictionary
let today = snapshotValue!["today"] as? String
snapshotValue = snapshot.value as? NSDictionary
let limit = snapshotValue!["limit"] as? String
snapshotValue = snapshot.value as? NSDictionary
self.limits.insert(limitStruct(name:name, today:today, limit: limit), at: self.limits.count)
self.tableView.reloadData()
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return limits.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Limit")
let label1 = cell?.viewWithTag(1) as! UILabel
label1.text = limits[indexPath.row].name
let label2 = cell?.viewWithTag(2) as! UILabel
label2.text = limits[indexPath.row].today
let label3 = cell?.viewWithTag(3) as! UILabel
label3.text = limits[indexPath.row].limit
return cell!
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetails"{
let svc = segue.destination as! CirSliderViewController;
if let indexPath = self.tableView.indexPathForSelectedRow{
// svc.RsegueData =
}
}
}
}
これまでに書いたコードを表示してください。 – mlidal
どのように情報をそのセルに入れましたか? 'tableView(_tableView:cellForRowAt:)'のコードは何ですか?配列(dataSource)からテキストを設定しましたか?その後、indexPathを取得するので、配列(dataSource)をリードしただけです。 – Larme
@Larme私はfirebaseからデータを取得しています。それは思ったよりも複雑に思えます。 – jlassap