title: dropdown array becomes empty for few cells after adding cells in tableview and scroll up
body: <p>Initially when I tap of hierarchy button and parentLocationLevelTwoBtnAction at that time parentLocationNameArr is not empty but after adding few more cells and I scroll up parentLocationNameArr is empty</p>
  <pre><code>import UIKit
  import DropDown
  import ObjectMapper
  
  //Stock Btn Cell Delegate
  protocol AddStorageLocationMasterBtnCellDelegate : AnyObject {
      func didPressButton(_ tag: Int)
      func didPressHierachyButton(_ tag: Int)
      func didPressHierachytext(_ tag: Int,sender:String)
      func didPressParenttext(_ tag: Int,sender:String, id:String)
      func didPressParentTwotext(_ tag: Int,sender:String, id:String)
  }
  
  class AddStorageLocationMasterTVCell: UITableViewCell {
      
      @IBOutlet var parentLTextLHeight: NSLayoutConstraint!
      @IBOutlet weak var bgView: UIView!
      @IBOutlet weak var deleteBtn: UIButton!
      @IBOutlet weak var storageLocationNameView: UIView!
      @IBOutlet var warnDescriptionbtn: UIButton!
      @IBOutlet weak var storageLocationNameTF: UITextField!
      @IBOutlet var warnNamebtn: UIButton!
      @IBOutlet weak var descriptionView: UIView!
      @IBOutlet weak var descriptionTextView: UITextView!
      @IBOutlet weak var hierachyView: UIView!
      @IBOutlet weak var hierachyTF: UITextField!
      @IBOutlet weak var hierachyBtn: UIButton!
      @IBOutlet weak var parentLocationView: UIView!
      @IBOutlet weak var parentLocationTF: UITextField!
      @IBOutlet weak var parentBgView: UIView!
      @IBOutlet weak var parentHeightConstant: NSLayoutConstraint!
      
      @IBOutlet weak var parentLocationLevelOneBtn: UIButton!
      @IBOutlet weak var parentLocationLevelTwoView: UIView!
      
      @IBOutlet weak var parentLocationLevelTwoTF: UITextField!
      @IBOutlet weak var parentLocationTextLabel: UILabel!
      
      @IBOutlet weak var stackView: UIStackView!
      @IBOutlet weak var stackViewHeight: NSLayoutConstraint!
      @IBOutlet weak var parentLcationLabel: UILabel!
      
      var cellDelegate: AddStorageLocationMasterBtnCellDelegate?
      
      let dropDown = DropDown() //2
      var selectedId = 0
      
      var accountID = &quot;&quot;
      var storageLocationArr = NSMutableArray()
      var storageLocationLevelThreeArr = NSMutableArray()
      var serviceVC = ServiceController()
      var parentLocationDict = [String]()
      var parentLocationId = [String]()
      var parentLocationArr = [NSArray]()
      
      var parentLocationNameArr = [String]()
      var parentLocationNameIdsArr = [String]()
      var parentLocationDetailsDict = NSMutableArray()
      
      var parentLocationNameLevethreeArr = [String]()
      var parentLocationNameLevethreeIdsArr = [String]()
      var parentLocationDetailsLevethreeDict = NSMutableArray()
      
      var levelValue = 0
      var idLevelThree = &quot;&quot;
      
      override func awakeFromNib() {
          super.awakeFromNib()
          // Initialization code
          
          self.parentBgView.isHidden = true
          self.parentHeightConstant.constant = 0
          
          storageLocationNameView.layer.borderColor = UIColor.gray.cgColor
          storageLocationNameView.layer.borderWidth = 0.5
          storageLocationNameView.layer.cornerRadius = 3
          storageLocationNameView.clipsToBounds = true
          
          descriptionView.layer.borderColor = UIColor.gray.cgColor
          descriptionView.layer.borderWidth = 0.5
          descriptionView.layer.cornerRadius = 3
          descriptionView.clipsToBounds = true
          
          hierachyView.layer.borderColor = UIColor.gray.cgColor
          hierachyView.layer.borderWidth = 0.5
          hierachyView.layer.cornerRadius = 3
          hierachyView.clipsToBounds = true
          
          parentLocationView.layer.borderColor = UIColor.gray.cgColor
          parentLocationView.layer.borderWidth = 0.5
          parentLocationView.layer.cornerRadius = 3
          parentLocationView.clipsToBounds = true
          
          parentLocationLevelTwoView.layer.borderColor = UIColor.gray.cgColor
          parentLocationLevelTwoView.layer.borderWidth = 0.5
          parentLocationLevelTwoView.layer.cornerRadius = 3
          parentLocationLevelTwoView.clipsToBounds = true
          
          bgView.backgroundColor = .white
          bgView.layer.cornerRadius = 5.0
          bgView.layer.shadowColor =  #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
          bgView.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
          bgView.layer.shadowRadius = 6.0
          bgView.layer.shadowOpacity = 0.7
          
          hierachyTF.text = &quot;Level 1&quot;
          selectedId = 1
      }
      
      @IBOutlet var parentButton: UIButton!
      //    override func setSelected(_ selected: Bool, animated: Bool) {
      //        super.setSelected(selected, animated: animated)
      //
      //        // Configure the view for the selected state
      //    }
      @IBAction func deleteBtnAction(_ sender: UIButton) {
          
          cellDelegate?.didPressButton(sender.tag)
      }
      var tagVal=Int()
      
      @IBAction func hierachyBtnAction(_ sender: UIButton) {
          
          let selectedTagHierachy = sender.tag
          
          cellDelegate?.didPressHierachyButton(selectedTagHierachy)
          dropDown.dataSource = [&quot;Level 1&quot;,&quot;Level 2&quot;,&quot;Level 3&quot;]//4
          dropDown.anchorView = sender //5
          dropDown.bottomOffset = CGPoint(x: 0, y: sender.frame.size.height) //6
          dropDown.show() //7
          
          dropDown.selectionAction = { (index: Int, item: String) in //8
              //              guard let _ = self else { return }
              //              sender.setTitle(item, for: .normal) //9
              self.selectedId = index
              self.hierachyTF.text = item
              self.cellDelegate?.didPressHierachytext(selectedTagHierachy, sender: item)
              print(self.levelValue)
              if index == 0 {
                  
                  self.parentBgView.isHidden = true
                  self.parentHeightConstant.constant = 0
              }
              else if index == 1{
                  self.levelValue = index+1
                  self.get_StorageLocationMaster_API_Call(level: index+1, tag: selectedTagHierachy)
                  self.parentBgView.isHidden = false
                  self.parentHeightConstant.constant = 120
                  self.parentLcationLabel.text = &quot;Parent Location L1&quot;
                  self.parentLocationLevelTwoView.isHidden = true
              }
              else if index == 2{
                  self.levelValue = index+1
                  self.get_StorageLocationMaster_API_Call(level: index+1, tag: selectedTagHierachy)
                  self.parentBgView.isHidden = false
                  self.parentHeightConstant.constant = 120
                  self.parentLcationLabel.text = &quot;Parent Location L2 and L1&quot;
                  self.parentLocationLevelTwoView.isHidden = false
              }
          }
      }
      
      @IBAction func parentLocationBtnAction(_ sender: UIButton) {
          
          let selectedTagParentLocation = sender.tag
          //        cellDelegate?.didPressParenttext(&lt;#T##tag: Int##Int#&gt;, sender: sender, id: &lt;#T##String#&gt;)
          dropDown.dataSource = parentLocationNameLevethreeArr//4
          dropDown.anchorView = sender //5
          dropDown.bottomOffset = CGPoint(x: 0, y: sender.frame.size.height) //6
          dropDown.show() //7
          dropDown.selectionAction = {  (index: Int, item: String) in //8
              //              guard let _ = self else { return }
              //              sender.setTitle(item, for: .normal) //9
              self.parentLocationLevelTwoTF.text = item
              self.cellDelegate?.didPressParentTwotext(selectedTagParentLocation, sender: item, id:self.parentLocationNameLevethreeIdsArr[index] )
          }
          
          
      }
      
      @IBAction func parentLocationLevelTwoBtnAction(_ sender: UIButton)
      {
          
          let selectedTagParentLocation = sender.tag
          
          dropDown.dataSource = parentLocationNameArr//4
          dropDown.anchorView = sender //5
          dropDown.bottomOffset = CGPoint(x: 0, y: sender.frame.size.height) //6
          dropDown.show() //7
          dropDown.selectionAction = {  (index: Int, item: String) in //8
              //              guard let _ = self else { return }
              //              sender.setTitle(item, for: .normal) //9
              //                if self?.parentLocationNameLevethreeArr.count ?? 0&gt;0
              //                {
              //                self?.parentLocationLevelTwoTF.text = self?.parentLocationNameLevethreeArr[0]
              //                    self?.cellDelegate?.didPressParentTwotext(sender.tag, sender: self?.parentLocationNameLevethreeArr[0] ?? &quot;&quot;, id: self?.parentLocationNameLevethreeIdsArr[0] ?? &quot;&quot;)
              //                }
              self.parentLocationTF.text = item
              self.idLevelThree = self.parentLocationNameIdsArr[index]
              self.cellDelegate?.didPressParenttext(selectedTagParentLocation, sender: item, id: self.parentLocationNameIdsArr[index] )
              print(self.levelValue)
              if self.levelValue==3
              {
                  self.get_StorageLocationByParentLocation_API_Call(level: 2, tag: selectedTagParentLocation)
              }
              
          }
      }
      
      // MARK: Get Storage Location Master API Call
      func get_StorageLocationByParentLocation_API_Call(level:Int,tag:Int) {
          
          let defaults = UserDefaults.standard
          accountID = (defaults.string(forKey: &quot;accountId&quot;) ?? &quot;&quot;)
          //      let newString = parentLocation.replacingOccurrences(of: &quot; &quot;, with: &quot;%20&quot;)
          if idLevelThree != &quot;&quot;
          {
              let urlStr = Constants.BaseUrl + getAllStorageLocationByParentUrl + &quot;\(2)/&quot; + &quot;\(idLevelThree)/&quot; + accountID
              
              serviceVC.requestGETURL(strURL: urlStr, success: {(result) in
                  
                  let respVo:GetStorageLocationMasterRespVo = Mapper().map(JSON: result as! [String : Any])!
                  
                  DispatchQueue.main.async { [self] in
                      
                      let status = respVo.STATUS_CODE
                      let message = respVo.STATUS_MSG
                      
                      if status == 200 {
                          if message == &quot;SUCCESS&quot; {
                              if respVo.result != nil {
                                  if respVo.result!.count &gt; 0 {
                                      let resultObj:[String:Any]=result as? [String:Any] ?? [String:Any]()
                                      let resultArr:NSMutableArray=resultObj[&quot;result&quot;]as? NSMutableArray ?? NSMutableArray()
                                      self.storageLocationLevelThreeArr = NSMutableArray()
                                      self.storageLocationLevelThreeArr = resultArr
                                      
                                      self.parentLocationNameLevethreeArr.removeAll()
                                      self.parentLocationNameLevethreeIdsArr.removeAll()
                                      
                                      for obj in self.storageLocationLevelThreeArr {
                                          
                                          let sDict=obj as? NSDictionary
                                          
                                          let isCanEd:Bool = sDict?.value(forKey: &quot;canEdit&quot;) as? Bool ?? false
                                          //                                    sDict(sDict?[i] as AnyObject).value(forKey: &quot;canEdit&quot;) as? Bool
                                          
                                          if isCanEd == true {
                                              let slocName = sDict?.value(forKey: &quot;slocName&quot;) as? String ?? &quot;&quot;
                                              let idsStr = sDict?.value(forKey: &quot;_id&quot;) as? String ?? &quot;&quot;
                                              self.parentLocationNameLevethreeIdsArr.append(idsStr)
                                              self.parentLocationNameLevethreeArr.append(slocName)
                                              print(&quot;level 2 : \(parentLocationNameLevethreeArr)&quot;)
                                          }
                                      }
                                      
                                      if self.parentLocationNameLevethreeArr.count &gt; 0 {
                                          self.parentLocationLevelTwoTF.text = self.parentLocationNameLevethreeArr[0]
                                          self.cellDelegate?.didPressParentTwotext(tag, sender: self.parentLocationNameLevethreeArr[0], id: self.parentLocationNameLevethreeIdsArr[0])
                                      }
                                      //                            else{
                                      //                                self.parentLocationLevelTwoTF.text = &quot;&quot;
                                      //                            }
                                      self.parentLTextLHeight.constant=0
                                      self.parentLocationTextLabel.isHidden=true
                                      self.parentLocationTextLabel.text=&quot;&quot;
                                  }
                                  else {
                                      self.parentLTextLHeight.constant=40
                                      self.parentLocationTextLabel.isHidden=false
                                      self.parentLocationTextLabel.text=&quot;No parent storage location is created currently. Pls create a parent storage location before creating the storage location when use creates a storage location without a custom parent storage location&quot;
                                      self.parentLocationTextLabel.numberOfLines = 0
                                      self.parentLocationTextLabel.lineBreakMode = .byWordWrapping
                                      self.parentLocationLevelTwoTF.text = &quot;&quot;
                                      self.parentLocationNameLevethreeArr=[String]()
                                      self.parentLocationNameLevethreeIdsArr=[String]()
                                  }
                              }
                          }
                      }
                      else {
                          //                      self.view.makeToast(message)
                      }
                  }
              }) { (error) in
                  //            self.view.makeToast(&quot;app.SomethingWentToWrongAlert&quot;.localize())
                  print(&quot;Oops, your connection seems off... Please try again later&quot;)
              }
          }
          else
          {
              self.parentLTextLHeight.constant=40
              self.parentLocationTextLabel.isHidden=false
              self.parentLocationTextLabel.text=&quot;No level 2 storage location exists currently. Pls create a level 2 storage location before creating levele 3 storage location&quot;
          }
      }
      
      // MARK: Get AddressBook API Call
      func get_StorageLocationMaster_API_Call(level:Int,tag:Int) {
          
          let defaults = UserDefaults.standard
          accountID = (defaults.string(forKey: &quot;accountId&quot;) ?? &quot;&quot;)
          
          let urlStr = Constants.BaseUrl + getAllStorageLocationByHierachyLevelUrl + &quot;\(1)/&quot; + accountID
          
          serviceVC.requestGETURL(strURL: urlStr, success: {(result) in
              
              let respVo:GetStorageLocationMasterRespVo = Mapper().map(JSON: result as! [String : Any])!
              
              DispatchQueue.main.async {
                  
                  let status = respVo.STATUS_CODE
                  let message = respVo.STATUS_MSG
                  
                  if status == 200 {
                      if message == &quot;SUCCESS&quot; {
                          if respVo.result != nil {
                              if respVo.result!.count &gt; 0 {
                                  let resultObj:[String:Any]=result as? [String:Any] ?? [String:Any]()
                                  let resultArr:NSMutableArray=resultObj[&quot;result&quot;]as? NSMutableArray ?? NSMutableArray()
                                  print(resultArr)
                                  self.storageLocationArr = NSMutableArray()
                                  self.storageLocationArr = resultArr
                                  
                                  if  self.storageLocationArr.count==0
                                  {
                                      self.parentLTextLHeight.constant=40
                                      self.parentLocationTextLabel.isHidden=false
                                  }
                                  else
                                  {
                                      self.parentLTextLHeight.constant=0
                                      self.parentLocationTextLabel.isHidden=true
                                      let ddict=self.storageLocationArr[0] as? NSDictionary
                                      
                                      self.parentLocationNameArr = [String]()
                                      self.parentLocationNameIdsArr = [String]()
                                      
                                      for obj in self.storageLocationArr {
                                          
                                          let sDict=obj as? NSDictionary
                                          
                                          let isCanEd:Bool = sDict?.value(forKey: &quot;canEdit&quot;) as? Bool ?? false
                                          //                                    sDict(sDict?[i] as AnyObject).value(forKey: &quot;canEdit&quot;) as? Bool
                                          
                                          if isCanEd == true {
                                              let slocName = sDict?.value(forKey: &quot;slocName&quot;) as? String ?? &quot;&quot;
                                              let idsStr = sDict?.value(forKey: &quot;_id&quot;) as? String ?? &quot;&quot;
                                              self.parentLocationNameIdsArr.append(idsStr)
                                              self.parentLocationNameArr.append(slocName)
                                              print(self.parentLocationNameArr)
                                              self.parentLocationDetailsDict.addObjects(from: sDict?.value(forKey: &quot;parentLocationDetails&quot;) as? NSMutableArray as! [Any])
                                          }
                                      }
                                      let parentLocationDetails=ddict?.value(forKey: &quot;parentLocationDetails&quot;)as? NSArray
                                      print(self.levelValue)
                                      if self.levelValue==3
                                      {
                                          if self.parentLocationNameArr.count&gt;0
                                          {
                                              self.idLevelThree = self.parentLocationNameIdsArr[0] ?? &quot;&quot;
                                              self.parentLocationTF.text = self.parentLocationNameArr[0]
                                              self.cellDelegate?.didPressParenttext(tag, sender: self.parentLocationNameArr[0], id: self.parentLocationNameIdsArr[0])
                                          }
                                          else{
                                              self.parentLTextLHeight.constant=40
                                              self.parentLocationTextLabel.isHidden=false
                                              self.parentLocationTextLabel.text=&quot;No level 2 storage location exists currently. Pls create a level 2 storage location before creating levele 3 storage location&quot;
                                          }
                                          //                                    if self.parentLocationDetailsDict.count &gt; 0
                                          //                                    {
                                          self.get_StorageLocationByParentLocation_API_Call(level: 2, tag:tag)
                                          print(&quot;parent level 2 :\(self.parentLocationNameLevethreeArr)&quot;)
                                          //                                    }
                                          
                                      }
                                      else
                                      {
                                          if self.parentLocationNameArr.count&gt;0
                                          {
                                              self.parentLocationTF.text = self.parentLocationNameArr[0]
                                              self.cellDelegate?.didPressParenttext(tag, sender: self.parentLocationNameArr[0], id: self.parentLocationNameIdsArr[0])
                                          }
                                          else{
                                              self.parentLTextLHeight.constant=40
                                              self.parentLocationTextLabel.isHidden=false
                                              self.parentLocationTextLabel.text=&quot;No level 1 storage location exists currently. Pls create a level 1 storage location before creating levele 3 storage location&quot;
                                          }
                                      }
                                      
                                  }
                              }
                              else {
                                  
                              }
                          }
                      }
                  }
                  else {
                      //                    self.view.makeToast(message)
                  }
              }
          }) { (error) in
              //            self.view.makeToast(&quot;app.SomethingWentToWrongAlert&quot;.localize())
              print(&quot;Oops, your connection seems off... Please try again later&quot;)
          }
      }
  }
  </code></pre>
  <p>Thanks in advance</p>