title: Expanding List UITableView is duplicating
body: <p>I want to create a dynamic table that expands another data when it selected.</p>
  
  <p>I've follow this tutorial <b> <a href="https://www.youtube.com/watch?v=ClrSpJ3txAs" rel="nofollow noreferrer">https://www.youtube.com/watch?v=ClrSpJ3txAs</a> </b> but i cant make dynamic (each data is duplicating)</p>
  
  <p>Here's what i want to make <a href="https://i.stack.imgur.com/NgLU0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NgLU0.png" alt="What i want"></a></p>
  
  <p>And here's what i've been made
  <img src="https://i.stack.imgur.com/wjDSP.png" alt="This is what I’ve been create"></p>
  
  <p>The data itself is duplicating and i dont know how to fix it because when i change some code inside tableView(), it'll crash when i select it or when i'm segue into this view.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>import UIKit
  import PopupDialog
  
  
  struct cellData {
  
        var isOpened            = Bool()
        var title             = [String]()
        var sectionData = [String]()
  }
  
  class TutorialBankTableViewController: UITableViewController {
  
        var user = DBManager.instance.getUserProfile()
        var tableViewData = [cellData]()
        var extendedData = ""
        var sendTitleNameForGettingExtendedData = ""
        var arrayextendedData: [String] = []
        var titleName: [String] = []
  
        override func viewDidLoad() {
            super.viewDidLoad()
  
  
            reloadTableView()
  
            // Do any additional setup after loading the view.
        }
  
        func reloadTableView() {
  
  
            if titleName.isEmpty == true {
  
                requestTitleName()
  
            } else {
  
                tableViewData = [cellData(isOpened: false, title: titleName, sectionData: arrayextendedData),
                                 cellData(isOpened: false, title: titleName, sectionData: arrayextendedData),
                                 cellData(isOpened: false, title: titleName, sectionData: arrayextendedData),
                                 cellData(isOpened: false, title: titleName, sectionData: arrayextendedData),
                                 cellData(isOpened: false, title: titleName, sectionData: arrayextendedData)]
  
                DispatchQueue.main.async { self.tableView.reloadData() }
  
            }
  
        }
  
  
  
  
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
  
        // MARK: - Table view data source
  
        override func numberOfSections(in tableView: UITableView) -&gt; Int {
            // #warning Incomplete implementation, return the number of sections
            return tableViewData.count
        }
  
        override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
            // #warning Incomplete implementation, return the number of rows
            if tableViewData[section].isOpened {
  
                return (tableViewData[section].sectionData.count + 1)
            }
            return 1
        }
  
        override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
            if indexPath.row == 0 {
                guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else {
                    return UITableViewCell()
                }
                cell.textLabel?.text = tableViewData[indexPath.section].title[indexPath.row]
                return cell
            } else {
                guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else {
                    return UITableViewCell()
                }
  
                self.tableView.contentInset = UIEdgeInsetsMake(0, 16, 0, 0);
  
                cell.textLabel?.text = tableViewData[indexPath.section].sectionData[indexPath.row - 1]
                return cell
  
            }
        }
  
        override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  
            if indexPath.row == 0 {
  
                if tableViewData[indexPath.section].isOpened {
  
                    let indexPath = tableView.indexPathForSelectedRow //optional, to get from any UIButton for example
  
                    let currentCell = tableView.cellForRow(at: indexPath!) as! UITableViewCell
  
                    print(currentCell.textLabel!.text)
  
                    sendTitleNameForGettingExtendedData = currentCell.textLabel!.text!
  
                    requestExtendedData()
  
                } else {
  
                    tableViewData[indexPath.section].isOpened = true
  
                }
                    let sections = IndexSet(integer: indexPath.section)
                    tableView.reloadSections(sections, with: .none)
            }
        }
        func requestTitleName(){
  
            NetworkingService.shared.reqTitle(phone_number: user!.phone_number ?? "") { spinnerResponse in
  
                if (spinnerResponse == nil){
  
                    self.view.makeToast("Technical problem, please try again...")
  
                } else {
  
                    if (spinnerResponse?.success == Const.ResponseKey.Success){
  
                        print(spinnerResponse ?? "")
  
                        if let apiResponseData = spinnerResponse!.data{
  
                            self.titleName.removeAll()
  
                             // filtering data what I want to put
                            _ = apiResponseData.filter { (dic) -&gt; Bool in
                                if dic.types == “Testing Request“ {
  
                                    self.titleName.append(dic.listName ?? "")
  
                                }
                                return true
                            }
                        }
  
                        print(self.titleName)
                        self.reloadTableView()
  
  
                    } else if (spinnerResponse?.success == Const.ResponseKey.SessionEnd) {
                        self.sessionEnd()
                    } else{
  
                        let popup             = PopupDialog(title: "Gagal Meminta Data ", message: spinnerResponse?.error)
                        let buttonOK          = DefaultButton(title: "OK"){
  
                        }
                        popup.addButton(buttonOK)
  
                        self.present(popup,animated: true,completion: nil)
  
                    }
  
                }
            }
  
        }
  
        func requestExtendedData() {
  
            print(TransactionNumber.instance.genTransNumber(_jenisTransaksi: .BANK, _phoneNumber: (user?.phone_number)!))
  
            NetworkingService.shared.requestExtendedDataCashin(phone_number: user!.phone_number!, jenis_trx: "VI", nama_lk: sendTitleNameForGettingExtendedData) { responseTutorial in
  
                if (responseTutorial == nil) {
  
                    self.view.makeToast("Technical problem, please try again...")
                } else {
  
                    if responseTutorial?.success == Const.ResponseKey.Success {
  
                        self.extendedData = (responseTutorial?.token)!
  
                        // convert into array for showing all text in responseTutorial.token
                        var delimiter = "\n"
                        self.arrayextendedData = (responseTutorial?.token!.components(separatedBy: delimiter))!
  
                        self.reloadTableView()
  
                    } else if responseTutorial?.success == Const.ResponseKey.SessionEnd {
  
                        self.sessionEnd()
  
                    } else if responseTutorial?.success == Const.ResponseKey.Error {
  
                        self.view.makeToast((responseTutorial?.token)!)
                    }
                }
            }
        }
  }
  </code></pre>
  
  <p>How can i fix this duplicating data?
  Thank you.</p>