我正在制作一个应用程序来跟踪我的作业,出于某种原因,当我打电话给reloadData它没有工作时,有些人已经问过这个问题,但是我已经尝试了修复它们并且他们没有为我工作,这是我添加新作业的文件:
import UIKit
class AddHomework : UIViewController {
@IBOutlet weak var HomeworkNameLbl: UILabel!
@IBOutlet weak var HomeworkNameTxt: UITextField!
@IBOutlet weak var DueDateLbl: UILabel!
@IBOutlet weak var DueDateTxt: UITextField!
@IBOutlet weak var DueTimeLbl: UILabel!
@IBOutlet weak var DueTimeTxt: UITextField!
@IBOutlet weak var AddHomeworkBtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
self.hideKeyboardWhenTappedAround()
}
@IBAction func AddHomework(sender: UIButton) {
let HomeworkName = HomeworkNameTxt.text
let DueDate = DueDateTxt.text
let DueTime = DueTimeTxt.text
homeworkTableView().AddObject([DueDate!, DueTime!], HomeworkName: HomeworkName!)
}
func hideKeyboardWhenTappedAround() {5
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
view.addGestureRecognizer(tap)
}
func dismissKeyboard() {
view.endEditing(true)
}
}
这是我的tableview文件:
import UIKit
class homeworkTableView: UIViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.reloadData()
}
var homework : [String: [String]] = [
"Spanish Test": ["Aug 12", "12:00 AM", "Spanish"],
"Math Sheet": ["Aug 13", "10:30 PM","Math"],
"Code Thing": ["Aug 11","12:00 AM","Coding"]
]
var titles = [
"Spanish Test", "Math Sheet", "Code Thing"
]
func AddObject(newArray: [String], HomeworkName: String){
titles.append(HomeworkName)
homework.updateValue(newArray, forKey: HomeworkName)
print(homework)
print(titles)
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titles.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let Cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
Cell.Title.text = titles[indexPath.row]
let currentTitle = titles[indexPath.row]
let current = homework[currentTitle]!
Cell.DueDate.text = "Due Date: \(current[0])"
Cell.Class.text = "Due Time: \(current[1])"
self.tableView.rowHeight = 100.00
return Cell
}
}
整个项目发布在git上: https://github.com/IndyBob2019/HomeworkHelper
非常感谢任何帮助,谢谢!