gpt4 book ai didi

swift - 无法快速触发按下表格单元格的 Action

转载 作者:行者123 更新时间:2023-11-28 12:17:49 27 4
gpt4 key购买 nike

我无法在单击表格单元格时触发操作。按下单元格后,被按下单元格的背景只是灰色。但是 Action 没有执行。请帮忙。

import UIKit

class ViewController: UIViewController, UITableViewDataSource , UITableViewDelegate
{
override func viewDidLoad() {
super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

var loki_images:[UIImage] = [UIImage(named: "images.png")!,
UIImage(named: "images (1).png")!,
UIImage(named: "images (2).png")!]

var persons = [ "Lokesh Ahuja" , "Raghav Mittal" , "Tul-Tul" ]

var identities = ["A","B","C"]

func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return persons.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell")

let Name = persons[indexPath.item]

cell!.textLabel!.text = Name

let image = loki_images[indexPath.row]

cell!.imageView?.image = image

return cell!
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
let id = identities[indexPath.item]
let viewController = storyboard?.instantiateViewControllerWithIdentifier(id)
self.navigationController?.pushViewController(viewController!, animated: true)
}
}

最佳答案

您的 UIViewController 是否在导航 Controller 中

如果不是那么你应该更换

self.navigationController?.pushViewController(viewController!, animated: true)

self.present(viewController, animated: true, completion: nil)

关于swift - 无法快速触发按下表格单元格的 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45855282/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com