gpt4 book ai didi

ios - UITableView 的问题

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

因此,我在我的 ViewController 中建立了一个 UITableView,并且 UITableView 值是使用数组填充的。每当用户触摸其中一个单元格时,他们就应该被带到另一个 View Controller 。好吧,当应用程序加载并单击第一个单元格时,什么也没有发生,如果单击第二个单元格,则会出现与第一个单元格关联的 View Controller ,然后它就从那里走下坡路。我似乎无法找到解决问题的方法,所以我想我会问问可能能够为我指明正确方向的人。这是相关的代码。提前致谢!

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

private let choices = ["About this App", "Touch Counting", "Slider Counting", "Calculator", "Date Picker"]
private let simpleTableID = "simpleTableID"

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

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier(simpleTableID)

if cell == nil {
cell = UITableViewCell(style: .Default, reuseIdentifier: simpleTableID)
}
cell?.textLabel?.text = choices[indexPath.row]
return cell!
}

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
switch(indexPath.row) {
case 0:
let vc = storyboard?.instantiateViewControllerWithIdentifier("AboutThisApp")
presentViewController(vc!, animated: true, completion: nil)
case 1:
let vc = storyboard?.instantiateViewControllerWithIdentifier("TouchCounting")
presentViewController(vc!, animated: true, completion: nil)
case 2:
let vc = storyboard?.instantiateViewControllerWithIdentifier("SlidingCounter")
presentViewController(vc!, animated: true, completion: nil)
case 3:
let vc = storyboard?.instantiateViewControllerWithIdentifier("Calculator")
presentViewController(vc!, animated: true, completion: nil)
case 4:
let vc = storyboard?.instantiateViewControllerWithIdentifier("Date")
presentViewController(vc!, animated: true, completion: nil)
default:
NSLog("NEVER!")
}
}
}

最佳答案

改变:

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

到:

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

didSelectRowAtIndexPath 在用户选择表格 View 行时被调用,但是 didDeselectRowAtIndexPath 在取消选择行时被调用,一旦用户点击第二行。

关于ios - UITableView 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36296762/

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