I altered some things in your example ViewController.swift to give you the perspective I'm facing, those were the changes:
var titleArray = ["GIOVANNIJ","MARCO","IBITCI","GOD","DID","RUAN","APPEND","BIAJ","LELE","TETE"]
func generateCardInfo (cardCount:Int) -> [AnyObject] {
var arr = [AnyObject]()
let xibName = ["CardA"]
for _ in 1...cardCount {
let value = Int(arc4random_uniform(UInt32(xibName.count)))
arr.append(xibName[value] as AnyObject)
}
return arr
}
func cardView(collectionView:UICollectionView,item:AnyObject,indexPath:IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: item as! String, for: indexPath )
switch cell {
case let c as CardACell:
c.txtView.text = "Hello This is MMCardView ,Its a demo with different Card Type,This is a text type"
c.labTitle.text = titleArray[indexPath.row]
case let c as CardBCell:
let v = Int(arc4random_uniform(5))+1
c.imgV.image = UIImage.init(named: "image\(v)")
case let c as CardCCell:
c.clickCallBack {
if let vc = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Second") as? SecondViewController {
vc.delegate = self
self.card.presentViewController(to: vc)
}
}
default:
return UICollectionViewCell()
}
return cell
}
@IBAction func filterAction () {
let sheet = UIAlertController.init(title: "Filter", message: "Select you want to show in View", preferredStyle: .alert)
sheet.addTextField(configurationHandler: nil)
let byText = UIAlertAction(title: "Filter by text", style: .default, handler: {
(alert: UIAlertAction!) -> Void in
self.card.filterAllDataWith(isInclued: { (idex, obj) -> Bool in
let titleTxt = self.titleArray[idex]
return titleTxt.lowercased().contains(sheet.textFields![0].text!)
})
})
let allCell = UIAlertAction(title: "Show all cells", style: .default, handler: {
(alert: UIAlertAction!) -> Void in
self.card.showAllData()
})
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: {
(alert: UIAlertAction!) -> Void in
})
sheet.addAction(byText)
sheet.addAction(allCell)
sheet.addAction(cancelAction)
self.present(sheet, animated: true, completion: nil)
}
Now this is what I'm facing:
- You have a pile of the same type cards differentiating them only by some sort of text (all of these are stored in an array).
- You choose to filter those cards by some text, looking for the cards that contains that text you typed.
- The filtering is done properly.
- You choose to show all your cards, to go back to the original state.
- Apparently everything is okay, but some cards are duplicated and some are missing.
Can you help me with this?