没有在TextView Xcoed 8中显示我的数据

时间:2017-03-22 18:33:45

标签: database sqlite swift3 textview xcode8

我不知道是什么问题,我将我的SQLite数据库与Swift 3连接起来,我在主故事板TextView中使用。 我创建了2个类(DatabaseModel& DatabaseHelper),Database Model是数据库sqlite中的定义行,DatabaseHelper是与我的数据库连接的一些代码,当我运行我的项目时,模拟器为空为什么?!! 请帮帮我!

import UIKit

class MenuViewController: UIViewController {

        @IBOutlet weak var textView: UITextView!

        var listDatabase = [DatabaseModel]()
        var dbHelper = DatabaseHelper()
        var data: DatabaseModel?

        override func viewDidLoad() {
            super.viewDidLoad()

            // Do any additional setup after loading the view.

            loadDtabase()

        }


        func loadDtabase() {

            listDatabase = dbHelper.getDatabase()

            do {

                textView.text = data?.ques
                textView.textColor = UIColor.black
                textView.font = UIFont.boldSystemFont(ofSize: 20)

                print("It's do it :)")

            } catch {

                print("NO Data !!!")

            }

        }

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

    }

1 个答案:

答案 0 :(得分:1)

试试这段代码:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var TextView: UITextView!

    var dbHelper = DatabaseHelper()
    var listDatabase = [DatabaseModel]()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        listDatabase = dbHelper.getDatabase()



        do {

            for data in listDatabase {

                TextView.text = data.ques
                TextView.backgroundColor = UIColor.yellow
                TextView.textColor = .green
                TextView.font = UIFont.boldSystemFont(ofSize: 20)
                print("Database is succseded connection...")

            }

        } catch {

            print("Get all database fail !!!")

        }


    }

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


}