Answer the question
In order to leave comments, you need to log in
Sort UITableView rows with UISegmentControl?
I want to implement sorting records by dates, while using UISegmentControl.
The UISegmentControl contains three columns: All , Today , Nearest
When sorting the rows, I use 3 - NSMutableArray
person - here is the list of people to start with cellForRowAtIndexPath .
original_person - backup list (copy of person). For those case when the main list is empty or has been changed.
b_person - it will store those lines that match the condition.
Question: Why is it giving this error?
Could not cast value of type '__NSDictionaryM' (0x101bafd38) to 'NSMutableArray' (0x101baf978).
if (ok==1) { b_person = h as! NSMutableArray }
b_person.removeAllObjects()
person = original_person
var shortDate: String {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd"
return dateFormatter.stringFromDate(NSDate())
}
var day1: NSInteger = 0;
var day2: NSInteger = 0;
var day3: NSInteger = 0;
var day4: NSInteger = 0;
var date: String = "";
var ok: Int = 0;
let dayNow: NSInteger = Int(shortDate)!;
for h in person {
ok = 0;
let date1 = h["date"] as? NSString
let date2 = h["date2"] as? NSString
let date3 = h["date3"] as? NSString
let date4 = h["date4"] as? NSString
if (date1!.componentsSeparatedByString(".")[0] != "") {
day1 = Int(date1!.componentsSeparatedByString(".")[0])!;
} else { day1 = 0 }
if (date2!.componentsSeparatedByString(".")[0] != "") {
day2 = Int(date2!.componentsSeparatedByString(".")[0])!;
} else { day2 = 0 }
if (date3!.componentsSeparatedByString(".")[0] != "") {
day3 = Int(date3!.componentsSeparatedByString(".")[0])!;
} else { day3 = 0 }
if (date4!.componentsSeparatedByString(".")[0] != "") {
day4 = Int(date4!.componentsSeparatedByString(".")[0])!;
} else { day4 = 0 }
if (day1>=dayNow) {date=date1! as String; ok = 1;}
if (day2>=dayNow) {date=date2! as String; ok = 1;}
if (day3>=dayNow) {date=date3! as String; ok = 1;}
if (day4>=dayNow) {date=date4! as String; ok = 1;}
if (ok==1) { b_person = h as! NSMutableArray }
}
person = b_person
self.tableView!.reloadData()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question