How can I update the numberOfRowsInSection and how do I show all added values in this tableView?

后端 未结 2 1149
旧时难觅i
旧时难觅i 2021-01-26 10:47

I am trying to send values from one view controller - NewZoomAddressViewController to another one - Add_EditAddressViewController. I am sending the val

2条回答
  •  轮回少年
    2021-01-26 11:21

    addressArray gets deallocated everytime you move back to the screen. You should declare it in Add_EditAddressViewController and append the data there only then send it to otherviewcontroller

      var addressArray : [String] = []
    
      @IBAction func confirmBtn(_ sender: Any) {
    
        let viewController = self.storyboard?.instantiateViewController(withIdentifier: "Add_EditAddressViewController") as! Add_EditAddressViewController;
        self.addressArray.append("\(sublocalityName ?? "") \(zipName ?? "") \(localityName ?? "")")
        vc.addressArray = self.addressArray
        self.navigationController?.pushViewController(viewController, animated: true);
    
    }
    

    And then in your otherViewController

    var addressArray : [String] = [] { 
          didSet { 
              self.addressEDITTableview.reloadData()
          }
     }
     override func viewDidLoad() {
        super.viewDidLoad()
      }
    
      extension Add_EditAddressViewController : UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    
        return addressArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
        let cell: EditAddressTableViewCell = tableView.dequeueReusableCell(withIdentifier: "EditAddressTableViewCell") as! EditAddressTableViewCell
        cell.nameHeader.text = "header"
        cell.addressLabel.text = addressArray[indexPath.row]
      return cell
     }
     }
    

提交回复
热议问题