如何在DetailView中显示我的整个数组

时间:2017-11-24 22:04:29

标签: arrays swift

我正在开发ToDo List应用程序。目前,ToDo列表在表视图中显示为列表,详细视图仅显示第一个项目,已完成的开关和完成的日期。我希望我的详细信息视图显示所有已完成的项目和日期,而不仅仅是第一项。

我的应用代表看起来像这样:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    let splitViewController = self.window!.rootViewController as! UISplitViewController
    let navigationController = splitViewController.viewControllers.first as! UINavigationController

    let masterViewController = navigationController.topViewController as! MasterViewController
    let detailViewController = splitViewController.viewControllers.last as! DetailViewController

    let firstItem = masterViewController.listManager.getFirstItem()
    detailViewController.toDoItem = firstItem

    return true
}

现在,我尝试将firstItem更改为toDoItem以显示我的整个数组,但是我收到错误:

无法指定类型' [ToDoItem]'的值输入' ToDoItem!'

另外,我在Detail View中创建什么来容纳每个变化的数组?

这是我目前的详细信息视图:

import UIKit

class DetailViewController: UIViewController {

@IBOutlet weak var descriptionLabel: UILabel!
@IBOutlet weak var dateAddedLabel: UILabel!
@IBOutlet weak var completedSwitch: UISwitch!

var toDoItem: ToDoItem! {
    didSet(newItem) {
        self.refreshUI()
    }
}

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    refreshUI()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func refreshUI() {

    if(toDoItem == nil) {
        return
    }
    descriptionLabel?.text = toDoItem.itemDescription
    completedSwitch?.setOn(toDoItem.completed, animated: true)
    dateAddedLabel?.text = toDoItem.getDateAdded()
}

0 个答案:

没有答案