Search code examples
swiftparse-platformios8xcode6uipickerview

Missing data from Parse to UIPickerView in Swift


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

I've pass the data from the Parse which the class name called 'Timetable' and the data will be get from the column name called 'Intake'. The picker view is able to get the data from it, however there're still a lot of data are still missing which not showing in the picker view. Does anyone know what problem is this?

***I've pointed the uipickerview delegate and datasource to self

The code will be shown below...

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!)
                }
        }

And these is the data source and delegates function of picker view will shown below...

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
    }

Solution

  • You can add this code to maximise the number of object into the array from Parse.

    var limit:NSInteger = 1000
            var skip:NSInteger = 0
            query.limit = limit
            query.skip = skip