簡體   English   中英

如何從 tableview didselect 行中的字典數組中傳遞特定字典?

[英]How to pass particular dictionary from array of dictionaries in tableview didselect row?

我有一個字典數組,我將這些數據加載到UITableView中。

我想在 select 行方法中將特定的數據字典發送到下一個視圖 controller。 我編寫了以下代碼,但給出了錯誤錯誤圖像

一旦找到我的以下代碼。

     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = mytableview.dequeueReusableCell(withIdentifier: "AddresBookCell")as! AddresBookCell
                if let value = self.alladdress, value.count > 0{

                cell.editbutton.addTarget(self, action: #selector(updateAddress(sender:)), for: .touchUpInside)
                cell.editbutton.tag = indexPath.row

                return cell
            }
        }

 @objc func updateAddress(sender:UIButton)
    {
        let vc = self.storyboard?.instantiateViewController(withIdentifier: "NewAddress")as! NewAddress
        vc.titlename = "Update Address"
        vc.alladdresses = self.alladdress[sender.tag]
        self.navigationController?.pushViewController(vc, animated: true)

    }

作為您發送的錯誤圖像,如果我正確,我認為您嘗試將項目 Alladd 設置為在 SecondVC 中列出 [Alladd]。 嘗試替換此代碼:

vc.alladdresses = self.alladdress[sender.tag]

對此:

vc.alladdresses = [self.alladdress[sender.tag]]

讓我知道我是否正確

嘗試這個:

在 SecondVC 中,您應該聲明屬性,該屬性將存儲傳遞的字典。

class SecondVC: UIViewController {
    var dict = NSDictionary()

}

在 FirstVC 中你應該這樣做:

 @objc func updateAddress(sender:UIButton)
    {
        let vc = self.storyboard?.instantiateViewController(withIdentifier: "NewAddress")as! NewAddress
        vc.titlename = "Update Address"
        vc.dict = self.alladdress[sender.tag]
        self.navigationController?.pushViewController(vc, animated: true)

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM