我的场景中,我试图创建tableview
单元格单击以获取label
数据,但我还有更多values
,但我不想在label
中显示。现在,我该如何assign
unshowed
将数据cell
到sending
,因为我是view controller
值到单元格didselect
之后的另一个 let alpha: [String] = ["A", "B", "C", "D", "E"]
let numeric: [String] = ["1", "2", "3", "4", "5"]
。
例如:
我有两个数组值
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:MyCustomCell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as! MyCustomCell
cell.textlabel.text = alpha[indexPath.row]
return cell
}
在这里,我只将alpha值播种到tableview单元格中
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let currentCell = tableView.cellForRow(at: indexPath)! as? MyCustomCell
print(currentCell?.textlabel?.text ?? "unknown alpha")
// Here I need to get numeric values also
}
现在,我要获取tableview单元格选定的值,在这里,我可以获取cell.textlabel.text值,但我还需要获取数字值,而无需分配任何标签。
// Create 'Customers' queue
Queue2<Customer> Customers = new Queue2<Customer>();
// Initializations of customers
Customer customer1 = new Customer(912, 6, 15);
// Add customers to queue
Customers.enqueue(customer1);
// Customer at teller 'i'
Customer C1 = new Customer(908, 3, 20);
// Denotes if teller 'i' is busy with a customer OR a task
int B1 = 1;
// Create 'Tasks' stack
Stack Tasks = new Stack();
// Initializiations of tasks
Task task1 = new Task(910, 12);
Task task2 = new Task(913, 3);
// Add tasks to stack
Tasks.push(task1);
Tasks.push(task2);
// Give tellers 1 and 2 an empty task to start
Task EmptyTaskT1 = new Task(0,0);
Task EmptyTaskT2 = new Task(0,0);
// Current task being worked on by teller 3
Task TaskCurr = new Task(916, 3);
// Initializations of Tellers
Teller tell1 = new Teller(C1, EmptyTaskT1, B1);
// Print Teller info
System.out.println(tell1);
// Printing just C1
System.out.println(C1);
答案 0 :(得分:-1)
通过使用以下代码,我们可以获得未显示的单元格索引数组值
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let currentCell = tableView.cellForRow(at: indexPath)! as? MyCustomCell
print(currentCell?.myCellLabel?.text ?? "unknown")
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "detailview") as! DetailViewController
newViewController.name = currentCell?.myCellLabel?.text ?? "unknown"
newViewController.country = self.numeric[indexPath.row]
self.present(newViewController, animated: true, completion: nil)
}