关闭UIAlertController后如何重新加载UIView

时间:2019-06-16 14:46:13

标签: swift uiview uialertcontroller

我尝试使用https://github.com/CoreCharts/CoreCharts制作BarChart,我有一个按钮,该按钮用textField调用UIAlertController。 单击提交按钮后,新数据将添加到阵列中。我需要重新启动图。

@IBAction func newWeightButton(_ sender: Any) {
        //updateGraph()
        let alert = UIAlertController(title: "Enter your new weight", message: nil, preferredStyle: .alert)
        alert.addTextField()


        let submitAction = UIAlertAction(title: "Add", style: .default) { [unowned alert] _ in
            let textField = alert.textFields![0]
            textField.keyboardType = UIKeyboardType.numberPad
            textField.becomeFirstResponder()
            let answer = Double(textField.text!)
            self.weightArr.append(answer!)
            print(self.weightArr)
            self.loadCoreChartData()
        }

        alert.addAction(submitAction)

        present(alert, animated: true)

}



func loadCoreChartData() -> [CoreChartEntry] {

        return getWeightList()

    }
func getWeightList()->[CoreChartEntry] {
    var allResults = [CoreChartEntry]()


    //let days = ["Mon","Tue","Wed","Thur","Fri"]
    let plateNumber = [80,75,90,88,84]
    var count = self.weightArr.count
    for index in 0..<count {

        let newEntry = CoreChartEntry(id: "\(self.weightArr[index])",
            barTitle: "Day",
            barHeight: Double(self.weightArr[index]),
            barColor:  UIColor(red: 0, green: 122/255, blue: 1, alpha: 1))


        allResults.append(newEntry)

    }

1 个答案:

答案 0 :(得分:0)

对于CoreCharts,请调用图表上的reload()

通常,在iOS中,设置UIView的属性足以使其更新,但是对于使用某种类型的数据源的视图(例如表,集合视图和核心图表),通常存在某种reload ...()函数告诉视图数据源已更改。