import UIKit
class TableViewController: UIViewController,UITableViewDataSource {
@IBOutlet weak var Logout: UIButton!
@IBOutlet weak var Addtask: UIButton!
@IBOutlet weak var tableView: UITableView!
var tasks: [Task] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
loadTasks()
tableView.register(UINib(nibName: "TableCell", bundle: nil), forCellReuseIdentifier: "cell")
}
func loadTasks() {
// Load tasks from local or remote data source
// Example:
// tasks = YourDataSource.loadTasks()
print("Loading tasks...")
let task = Task(title: "Sample Task", completed_by: "John Doe", date_completed: "2024-04-15", icon_name: "square", status_color: .green)
tasks.append(task)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tasks.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableCell
let task = tasks[indexPath.row]
print(task);
print("fmkfmkfd",cell);
cell.Title?.text = task.title
cell.Description?.text = "\(task.completed_by) on \(task.date_completed)"
cell.Icon?.image = UIImage(systemName: task.icon_name)
cell.Annotations?.image = UIImage(named: "annotation_icon") // Placeholder annotation image
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selectedTask = tasks[indexPath.row]
// Handle cell selection, e.g., navigate to details screen
}
@IBAction func logoutButtonTapped(_ sender: UIButton) {
// Perform logout action
// Implement logout functionality here
}
@IBAction func addButtonTapped(_ sender: UIButton) {
// Navigate to the Details screen to add a new task
// Implement navigation logic to Details screen
}
}
import Foundation
import UIKit
class TableCell: UITableViewCell {
@IBOutlet weak var Title: UILabel!
@IBOutlet weak var Description: UILabel!
@IBOutlet weak var Icon: UIImageView!
@IBOutlet weak var Annotations: UIImageView!
}
我已经正确连接了我的插座,并提供了自定义类名称并适当地重用了 ID,但我的表格仍然是空白的,如果我删除?下一个标题和所有其他字段实际上我在所有字段上都得到 nil error.nil 。但我的 IBoutlet 也连接了 id 命名,我仔细检查了代码中的单元 id,自定义类也相同,我不知道我做错了什么,这可能是一个小错误。我是 iOS 开发新手。
我正在使用故事板
cell
必须位于 Attributes Inspector (⌥⌘5) 的字段 Identifier 中,而不是位于 Identity Inspector (⌥⌘4) 的字段 Restoration ID