在Swift中丢失从Parse到UIPickerView的数据

时间:2015-04-14 13:41:40

标签: swift parse-platform ios8 xcode6 uipickerview

In this picture, there're many data are still missing in the picker view

我已经传递了Parse中的数据,该名称称为'时间表'并且数据将从名为' Intake'的列名称中获取。选择器视图能够从中获取数据,但仍有大量数据仍未丢失,而这些数据未在选择器视图中显示。有谁知道这是什么问题?

***我已将uipickerview委托和数据源指向自我

代码如下所示......

var pickerString:NSMutableArray = []

    override func viewDidLoad() {
        super.viewDidLoad()
        var query = PFQuery(className: "Timetable")
        query.findObjectsInBackgroundWithBlock
            {
                (objects:[AnyObject]?, error:NSError?) -> Void in
                if error == nil
                {
                    for object in objects! as [AnyObject]
                    {
                        if !self.pickerString.containsObject(object["Intake"] as! String) {
                            self.pickerString.addObject(object["Intake"] as! String)
                            //to avoid the duplication of the same data in picker view
                        }
                    }
                    self.pvIntakeCode.reloadAllComponents()
                }
                else
                {
                    NSLog("Error: %@ %@", error!, error!.userInfo!)
                }
        }

这些是数据源,选择器视图的委托功能如下所示......

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int
    {
        return 1
    }

    // returns the # of rows in each component..
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
    {
        return self.pickerString.count
    }


    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String!
    {
        return self.pickerString[row] as! String
    }

1 个答案:

答案 0 :(得分:2)

您可以添加此代码以最大化从Parse到数组的对象数。

const t = new Date().getDate() + (6 - new Date().getDay() - 1) - 7 ;
const lastFriday = new Date();
lastFriday.setDate(t);
console.log(lastFriday);