[英]Going to another view when I click a tableview cell
I know this question has been asked before but all the solutions I have found have really not made sense to me. 我知道这个问题以前曾被问过,但是我发现的所有解决方案对我来说实际上都是没有意义的。 I am a beginner at iOS and I know how I can left click and drag a button to another view to make a transition, but I can not do it with the tableview.
我是iOS的初学者,我知道如何左键单击并将按钮拖动到另一个视图以进行过渡,但是使用tableview无法做到这一点。 My layout is just two view controllers, one with a tableview and the second is blank, and I would eventually want to update labels for each tableview cell click.
我的布局只有两个视图控制器,一个具有表格视图,第二个为空白,我最终希望为每次单击表格单元格更新标签。
The code below is for the first view controller with everything to make a basic tableview work 下面的代码适用于第一个视图控制器,它具有使基本tableview正常运行的所有功能
import UIKit
var fullList = [String]()
var dateList = [String]()
class ViewController: UIViewController, UITableViewDelegate {
@IBOutlet var betTable: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if(NSUserDefaults.standardUserDefaults().objectForKey("fullList") != nil) //check if the to do list exists
{
fullList = NSUserDefaults.standardUserDefaults().objectForKey("fullList") as! [String] //store toDoList array into NSUserDefaults to save to iphone
}
if(NSUserDefaults.standardUserDefaults().objectForKey("dateList") != nil)
{
dateList = NSUserDefaults.standardUserDefaults().objectForKey("dateList") as! [String]
}
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return fullList.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
cell.textLabel?.text = fullList[indexPath.row]
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
{
if(editingStyle == UITableViewCellEditingStyle.Delete)
{
fullList.removeAtIndex(indexPath.row)
NSUserDefaults.standardUserDefaults().setObject(fullList, forKey: "fullList")
NSUserDefaults.standardUserDefaults().setObject(dateList, forKey: "dateList")
betTable.reloadData()
}
}
override func viewDidAppear(animated: Bool)
{
betTable.reloadData()
}
}
Select the type according to your requirement. 根据需要选择类型。
didSelectRowAtIndexPath
. didSelectRowAtIndexPath
。 Inside this you can call the func performSegueWithIdentifier
and provide the name you gave earlier. performSegueWithIdentifier
并提供您之前指定的名称。 Here is the code: Hope this helps. 希望这可以帮助。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.