Reputation: 39
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. 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
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()
}
}
Upvotes: 1
Views: 107
Reputation: 853
Select the type according to your requirement.
didSelectRowAtIndexPath
. Inside this you can call the func performSegueWithIdentifier
and provide the name you gave earlier. Here is the code:Hope this helps. :)
Upvotes: 1