[英]Going to another view when I click a tableview cell
我知道這個問題以前曾被問過,但是我發現的所有解決方案對我來說實際上都是沒有意義的。 我是iOS的初學者,我知道如何左鍵單擊並將按鈕拖動到另一個視圖以進行過渡,但是使用tableview無法做到這一點。 我的布局只有兩個視圖控制器,一個具有表格視圖,第二個為空白,我最終希望為每次單擊表格單元格更新標簽。
下面的代碼適用於第一個視圖控制器,它具有使基本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()
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.