有人可以帮助我,这条消息会一直提醒我。它可以列出您在一个页面注释中添加的应用程序,并在第二个页面上显示。 这是我的应用程序:
// FirstViewController.swift
import UIKit
class FirstViewController: UIViewController, UITableViewDataSource{
@IBOutlet var myTableView: UITableView!
func tableView(UITableView:tableView, commitEditingStyle editingStyle:UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
{
if editingStyle == UITableViewCellEditingStyle.delete
{
myItemList.removeAtIndex(indexPath.length.row)
myTableView.reloadData()
}
}
@available(iOS 2.0, *)
internal func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return myItemList.count
}
@available(iOS 2.0, *)
internal func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let myCell = UITableViewCell(style: UITableViewCellStyle.Default,reuseIdentifier: "myCell")
myCell.textLabel?.text = myItemList[indexPath.row]
return myCell
}
override func viewDidAppeeard(animated:boll){
// print("viewDidAppeeard")
myTableView.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
print("viewDidLoad")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
// SecondViewController.swift
// todolist
// Created by אייל זיידמן on 16.9.2016.
// Copyright © 2016 אייל זיידמן. All rights reserved.
import UIKit
class SecondViewController: UIViewController {
var myItemList = [String]()
@IBOutlet var myItemText: UITextField!
@IBAction func addItem(sender: AnyObject) {
if (myItemText.text?.characters.count)! > 0
{
myItemList.append(myItemText.text!)
myItemText.text = ""
self.view.endEditing(true)
print(myItemList)
}
}
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.
}
}