में छुआ या क्लिक किया गया है मैं TableView
में चयनित आइटम के index
प्राप्त करने का प्रयास कर रहा हूं और उसके बाद कुछ गतिविधि शुरू कर रहा हूं। दुर्भाग्य से मुझे मिले समाधानों में से अधिकांश उद्देश्य-सी में हैं या काम नहीं करते हैं।तालिका दृश्य कक्ष का पता लगाने के लिए कैसे स्विफ्ट
विधि func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
cell
लेबल मुद्रित नहीं है ..
किसी मेरी मदद कर सकते हैं?
import UIKit import ResearchKit class TaskListViewController: UIViewController, UITableViewDataSource { let tasks=[("Short walk"), ("Audiometry"), ("Finger tapping"), ("Reaction time"), ("Spatial span memory") ] //how many sections are in your table func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } //return int how many rows func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return tasks.count } //what are the contents func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell = UITableViewCell() var (testName) = tasks[indexPath.row] cell.textLabel?.text=testName return cell } // give each table section a name func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return "Tasks" } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let indexPath = tableView.indexPathForSelectedRow(); let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell! println(currentCell.textLabel!.text) } override func viewDidLoad() { super.viewDidLoad() } }
कुछ प्रयासों के बाद मैंने कोड को ट्यूटोरियल से अलग-अलग में बदल दिया। और यह भी काम नहीं करता है। अब मैं सोच रहा हूँ यह आईओएस सिम्युलेटर के साथ मुद्दा है ...
import UIKit import ResearchKit class TaskListViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet var tableView: UITableView? var items: [String] = ["We", "Heart", "Swift"] override func viewDidLoad() { super.viewDidLoad() self.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell") } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.items.count; } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell:UITableViewCell = self.tableView!.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell cell.textLabel?.text = self.items[indexPath.row] return cell } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { println("You selected cell #\(items[indexPath.row])!") } }
@ पॉविसून मुझे लगता है कि आपको सेलफोरो में समस्या है। अद्यतन उत्तर –