A
A
Archakov Dennis2016-07-11 22:57:03
Swift
Archakov Dennis, 2016-07-11 22:57:03

Swift: Why are the first 4 records displayed?

I'm sorting records by date. And the algorithm works correctly. Finds exactly 4 records by date: 07/11/2016 . But it adds the first 4 entries to the list.
There are two arrays. One with original content, the other changes depending on the conditions.

// Вызываем navSegmentC()

func navSegmentC(){
        let date = NSDate()
        var day : String = "0"
        
        let calendar = NSCalendar.currentCalendar()
        let components = calendar.components([.Day , .Month , .Year], fromDate: date)
        
        let month : String = (components.month < 10) ? "0\(components.month)" : String(components.month);
        
        switch navSegment.selectedSegmentIndex
        {
        case 0:
            sortType = 0;
            day = "\(String( components.day )).\(month)"
        case 1:
            sortType = 1;
            day = "\(String( Int( components.day ) + 1 )).\(month)"
        case 2:
            sortType = 2;
            day = "0";
        default:
            break;
        }
        self.sortByDate(day)
    }

func sortByDate(time:String){
        
        let dateFormatter = NSDateFormatter()
        dateFormatter.timeStyle = NSDateFormatterStyle.MediumStyle
        dateFormatter.dateStyle = NSDateFormatterStyle.MediumStyle
        dateFormatter.timeZone = NSTimeZone()
        
        self.patients = []
        
        for (index,element) in original_patients.enumerate() {
            
            dateFormatter.dateFormat = "dd.MM"
            let date = NSDate(timeIntervalSince1970: Double((element["date1"] as? String)!)!)
        
            let t1 = dateFormatter.stringFromDate(date).componentsSeparatedByString(".");
            let t2 = time.componentsSeparatedByString(".");

            if ( Int(t1[0])==Int(t2[0]) && Int(t1[1])==Int(t2[1]) )  {
                self.patients.addObject(self.original_patients[index])
            }
        }
        if (time == "0") { self.patients = self.original_patients }
        self.tableView.reloadData()
        
    }

84202f5373d14a808b244dfdba0ff33c.pngf1fb5b5e83bc40349bb37640578d3706.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question