     return cell
   }
   
+  func textFieldDidBeginEditing(textField: UITextField) {
+    var cellIndex = textField.superview as UICollectionViewCell
+    let temp = collectionView.indexPathForCell(cellIndex)?.row
+    delegate.currentIndex = temp!
+  }
+  
   func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
     if countElements(string) > 0 {
       let lastCharacter = string.substringFromIndex(advance(string.endIndex, -1))
       
       if lastCharacter == " " {
-        delegate.tags.append("")
-        collectionView.insertItemsAtIndexPaths([NSIndexPath(forRow: delegate.getTags().count, inSection: 0)])
+        var idx = delegate.currentIndex+1
+        if delegate.currentIndex == delegate.tags.endIndex {
+          idx = delegate.tags.endIndex
+        }
+        delegate.tags.insert("", atIndex: idx)
+        let indexPath = NSIndexPath(forRow: idx, inSection: 0)
+        collectionView.insertItemsAtIndexPaths([indexPath])
+        let cell = collectionView.cellForItemAtIndexPath(indexPath) as tagCell
+        cell.textField.becomeFirstResponder()
         return false
       }
     }

        collectionView.collectionViewLayout.invalidateLayout()
        width = resultFrame.size.width+12.0
      }
      textField.frame = CGRectMake(rectHold.origin.x, rectHold.origin.y, width, resultFrame.size.height)
      
      //      if textField.frame.width < rectHold.width {
      //        tagShrunk(textField)
      //      }
      //      checkTagSize(textField)
    }
  }
}

  }
  
  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    let test = delegate.getTags()
    
    var stringSize = ""
    if indexPath.row < delegate.getTags().count {
      stringSize = delegate.getTags()[indexPath.row]
    }
    var size = CGSizeMake(StartingWidth, 20)
    if stringSize != "" {
      size = getStringSize(stringSize)
    }
    return CGSizeMake(size.width + 10, 20)
  }
}

class TagDataSource: NSObject, UICollectionViewDataSource, UITextFieldDelegate {
