title: didselectatrow updating multiple cells below reloaded tableview + counter
body: <p>This is a two part question the first of which is after up to a full week of trying to figure this out I am still left with a blank. I finally got the individual cells to show the appropriate number related to the selection in the text field but still haven't figured out why the cells being reloaded into the tableview is also showing the updated text field. Basically I just want the text field for cardCounter updated only in the  row selected then if the user scrolls back to where that was if they decided to remove it it is showing them the counter for how many of that object is available. </p>
  
  <p>The second question is I am trying to make a counter for the cardCount that has a total limit of 30 and for each cardCount object selected 1 of those 30 selections has been narrowed down to 29, 28, 27 etc. Just trying to finish up some minor code on my first project.</p>
  
  <pre><code>import UIKit
  import CoreData
  
  class CardSelectionViewController: UIViewController, UITableViewDelegate, UIAlertViewDelegate, UISearchBarDelegate, NSFetchedResultsControllerDelegate {
  
  var passedDeckObject: Deck?
  let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
  
  var deckCardCount = 30
  
  @IBOutlet weak var cardsListed: UITableView!
  
  @IBOutlet weak var cardSearch: UISearchBar!
  
  
  @IBAction func backButton(sender: AnyObject) {
  }
  
  @IBAction func saveCardSelection(sender: AnyObject) {
  
      if deckCardCount != 30 {
  
      let selectmorecards = UIAlertController(title: "Select More Cards", message: "Please Select More Cards To Complete Deck", preferredStyle: .Alert)
      let okCardAction: UIAlertAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil)
          selectmorecards.addAction(okCardAction)
          self.presentViewController(selectmorecards, animated: true, completion: nil)
  
      } else {
  
      if deckCardCount == 30 {
      let alertController = UIAlertController(title: "All Cards Correct?", message: "Are all the cards in the deck what you wanted?", preferredStyle: .Alert)
      let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
      let okAction: UIAlertAction = UIAlertAction(title: "OK", style: .Default) { (action) -&gt; Void in
          self.managedObjectContext?.save(nil)
  
          self.presentViewController(alertController, animated: true, completion: nil)
  
          }
          }
      }
  }
  
  var costfrc: NSFetchedResultsController!
  var frc: NSFetchedResultsController = NSFetchedResultsController()
  func getFetchedResultsController() -&gt; NSFetchedResultsController {
      frc = NSFetchedResultsController(fetchRequest: listFetchRequest(), managedObjectContext: managedObjectContext!, sectionNameKeyPath: nil, cacheName: nil)
  
      return frc
  
  }
  func listFetchRequest() -&gt; NSFetchRequest {
  
      let requiredClassName = passedDeckObject!.classSelected.classname
      var requiredCardClasses = [Int]()
      let fetchRequest = NSFetchRequest(entityName: "Cards")
      let sortDescriptor = NSSortDescriptor(key: "name", ascending: true)
      switch(requiredClassName) {
          case "Warrior":
          requiredCardClasses = [1,10]
          case "Shaman":
          requiredCardClasses = [2,10]
          case "Rogue":
          requiredCardClasses = [3,10]
          case "Paladin":
          requiredCardClasses = [4,10]
          case "Hunter":
          requiredCardClasses = [5,10]
          case "Druid":
          requiredCardClasses = [6,10]
          case "Warlock":
          requiredCardClasses = [7,10]
          case "Mage":
          requiredCardClasses = [8,10]
          case "Priest":
          requiredCardClasses = [9,10]
          default:
          requiredCardClasses = [10]
      }
      fetchRequest.sortDescriptors = [sortDescriptor]
      fetchRequest.predicate = NSPredicate(format:"cardClass IN %@", requiredCardClasses)
  
      return fetchRequest
  }
  
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      let numberofRowsInSection = frc.sections?[section].numberOfObjects
      return numberofRowsInSection!
  }
  
  
  //Mark cell displayed with colored text//
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
      var cell: firstCardDetails = cardsListed.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! firstCardDetails
      let listed = frc.objectAtIndexPath(indexPath) as! Cards
      var cardCount = 0
      var myDeckCards: DeckCards?
      for eachDeckCard in listed.cardselections {
          let myDeckCard = eachDeckCard as! DeckCards
          if myDeckCard.cardsstored == passedDeckObject {
              myDeckCards = eachDeckCard as? DeckCards
              cardCount = myDeckCards!.numberSelected.integerValue
          }
      }
  
  
  
  
      cell.cardName?.text = listed.name as String
      if listed.cardType.isEqualToValue(1) {
          cell.cardAttack?.text = "*"
      } else {
          if listed.cardType.isEqualToValue(2) {
              cell.cardAttack?.text = "*"
          } else {
      cell.cardAttack?.text = listed.attack.stringValue
      }
      }
      if listed.cardType.isEqualToNumber(1) {
          cell.cardHealth?.text = "*"
      } else {
          if listed.cardType.isEqualToValue(2) {
              cell.cardHealth?.text = "*"
          } else {
      cell.cardHealth?.text = listed.health.stringValue
      }
      }
      cell.cardCost?.text = listed.cost.stringValue
  
          if listed.cardType.isEqualToNumber(0) {
              cell.cardType?.text = "Minion"
          } else {
              if listed.cardType.isEqualToNumber(1) {
                  cell.cardType?.text = "Spell"
              } else {
                  if listed.cardType.isEqualToNumber(2) {
                  cell.cardType?.text = "Weapon"
              }
              }
      }
      if listed.rarity.isEqualToNumber(1) {
          cell.rarityType?.text = "Legendary"
          cell.rarityType?.textColor = UIColor.orangeColor()
      } else {
          if listed.rarity.isEqualToNumber(2) {
              cell.rarityType?.text = "Epic"
              cell.rarityType?.textColor = UIColor.purpleColor()
          } else {
              if listed.rarity.isEqualToNumber(3) {
                  cell.rarityType?.text = "Rare"
                  cell.rarityType?.textColor = UIColor.blueColor()
              } else {
                  if listed.rarity.isEqualToNumber(4) {
                      cell.rarityType?.text = "Common"
                      cell.rarityType?.textColor = UIColor.grayColor()
                  } else {
                      if listed.rarity.isEqualToNumber(5) {
                          cell.rarityType?.text = "Starter"
                          cell.rarityType?.textColor = UIColor.blackColor()
                      }
                  }
              }
          }
      }
      if listed.cardClass.isEqualToNumber(1) {
          cell.cardName?.textColor = UIColor(red: 0xbe/255, green: 0x23/255, blue: 0x0f/255, alpha: 1.0)
      } else {
          if listed.cardClass.isEqualToNumber(2) {
              cell.cardName?.textColor = UIColor.blueColor()
          } else {
              if listed.cardClass.isEqualToNumber(3) {
                  cell.cardName?.textColor = UIColor(red: 0xE2/255, green: 0xA8/255, blue: 0x79/255, alpha: 1.0)
              } else {
                  if listed.cardClass.isEqualToNumber(4) {
                      cell.cardName?.textColor = UIColor(red: 0xFF/255, green: 0xAA/255, blue: 0x00/255, alpha: 1.0)
                  } else {
                      if listed.cardClass.isEqualToNumber(5) {
                          cell.cardName?.textColor = UIColor(red: 0x22/255, green: 0x63/255, blue: 0x29/255, alpha: 1.0)
                      } else {
                          if listed.cardClass.isEqualToNumber(6) {
                              cell.cardName?.textColor = UIColor.brownColor()
                          } else {
                              if listed.cardClass.isEqualToNumber(7) {
                                  cell.cardName?.textColor = UIColor(red: 0xBB/255, green: 0x76/255, blue: 0xE4/255, alpha: 1.0)
                              } else {
                                  if listed.cardClass.isEqualToNumber(8) {
                                      cell.cardName?.textColor = UIColor(red: 0x9E/255, green: 0xB5/255, blue: 0xFF/255, alpha: 1.0)
                                  } else {
                                      if listed.cardClass.isEqualToNumber(9) {
                                          cell.cardName?.textColor = UIColor.grayColor()
                                      } else {
                                          if listed.cardClass.isEqualToNumber(10) {
                                              cell.cardName?.textColor = UIColor.blackColor()
                                          }
                                          }
                                  }
                              }
  
                              }
                          }
                      }
                  }
          }
      }
      return cell
  }
  //reload content//
  func controllerDidChangeContent(controller: NSFetchedResultsController) {
      cardsListed.reloadData()
  }
  
  
  //selected row functions//
  func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
      var cardCount = 0
      var myDeckCards: DeckCards?
      let listed = frc.objectAtIndexPath(indexPath) as! Cards
  
  
      var cell = cardsListed.cellForRowAtIndexPath(indexPath) as! firstCardDetails
  
      cell.indexOfAccessibilityElement(listed)
  
      // check: is there already a DeckCards object for this Card and this Deck?
      let deckCardsSet = listed.cardselections
      println("The set of DeckCards for that Card is \(deckCardsSet.count)")
      for eachDeckCard in listed.cardselections {
          let myDeckCard = eachDeckCard as! DeckCards
          if myDeckCard.cardsstored == passedDeckObject {
              // There is already a DeckCard object for this Card and currentDeck
              myDeckCards = eachDeckCard as? DeckCards
          }
      }
      if myDeckCards == nil {
          // There is no DeckCard object for this Card and currentDeck
          // So create one...
          myDeckCards = NSEntityDescription.insertNewObjectForEntityForName("DeckCards", inManagedObjectContext: managedObjectContext!) as? DeckCards
          myDeckCards!.cardsselected = listed
          myDeckCards!.cardsstored = passedDeckObject!
      }
      // your code to determine numberSelected here; I'll assume 2!
      cardCount = myDeckCards!.numberSelected.integerValue
      deckCardCount = myDeckCards!.deckcardCount.integerValue
  
  
      cardCount = cardCount == 2 ? 0 : cardCount + 1
      myDeckCards!.numberSelected = cardCount
      deckCardCount = deckCardCount - cardCount
      cell.cardCounter.text = "  " + cardCount.description
          if deckCardCount == 30 {
              if cell.selected {
                  deckCardCount = deckCardCount + 1
              }
          myDeckCards!.numberSelected = deckCardCount
          myDeckCards!.numberSelected = cardCount
          }
      println(deckCardCount)
      println(cardCount)
  
  }
  
  //searchBar contoller//
  func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
  
      searchBar.setShowsCancelButton(true, animated: true)
      let requiredClassName = passedDeckObject!.classSelected.classname
      var requiredCardClasses = [Int]()
      switch(requiredClassName) {
      case "Warrior":
          requiredCardClasses = [1,10]
      case "Shaman":
          requiredCardClasses = [2,10]
      case "Rogue":
          requiredCardClasses = [3,10]
      case "Paladin":
          requiredCardClasses = [4,10]
      case "Hunter":
          requiredCardClasses = [5,10]
      case "Druid":
          requiredCardClasses = [6,10]
      case "Warlock":
          requiredCardClasses = [7,10]
      case "Mage":
          requiredCardClasses = [8,10]
      case "Priest":
          requiredCardClasses = [9,10]
      default:
          requiredCardClasses = [10]
      }
      if !searchText.isEmpty {
          // Clear out the fetchedResultController
          frc = getFetchedResultsController()
          // Setup the fetch request
          let fetchRequest = NSFetchRequest(entityName: "Cards")
          fetchRequest.fetchLimit = 565
          fetchRequest.predicate = NSCompoundPredicate(type: .AndPredicateType, subpredicates: [NSPredicate(format: "name contains[cd] %@", searchText), NSPredicate(format: "cardClass IN %@", requiredCardClasses)])
          let sortDescriptor = NSSortDescriptor(key: "name", ascending: true)
          fetchRequest.sortDescriptors = [sortDescriptor]
          println(fetchRequest.predicate)
          //end//
          //cost fetch request begins here//
          let costfetchRequest = NSFetchRequest(entityName: "cardCost")
          costfetchRequest.fetchLimit = 565
          costfetchRequest.predicate = NSPredicate(format: "cardCost = %i", searchText)
          let costSortDescriptor = NSSortDescriptor(key: "cardCost", ascending: true)
          costfetchRequest.sortDescriptors = [sortDescriptor]
          //end//
  
          // Pass the fetchRequest and the context as parameters to the fetchedResultController
          frc = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext:managedObjectContext!,
              sectionNameKeyPath: nil, cacheName: nil)
          // Make the fetchedResultController a delegate of the MoviesViewController class
          frc.delegate = self
          // Execute the fetch request or display an error message in the Debugger console
          var error: NSError? = nil
          if (!frc.performFetch(&amp;error)) {
              println("Error: \(error?.localizedDescription)")
          }
          // Refresh the table view to show search results
          cardsListed.reloadData()
      }
  }
  //search Cancel
  func searchBarCancelButtonClicked(searchBar: UISearchBar) {
      searchBar.text = nil
      searchBar.showsCancelButton = false // Hide the cancel
      searchBar.resignFirstResponder() // Hide the keyboard
  
      // Refresh the table view to show fetchedResultController results
      cardsListed.reloadData()
  }
  override func touchesBegan(touches: Set&lt;NSObject&gt;, withEvent event: UIEvent) {
  
      self.view.endEditing(true)
  }
  func textFieldShouldReturn(textField: UITextField) -&gt; Bool {
  
      textField.resignFirstResponder()
      return true
  }
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      println(passedDeckObject?.deckname)
      var nib = UINib(nibName: "firstCardDetails", bundle: nil)
      cardsListed.registerNib(nib, forCellReuseIdentifier: "cell")
      frc = getFetchedResultsController()
      frc.delegate = self
      frc.performFetch(nil)
  
  
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  }
  </code></pre>