[英]passing array values between view [swift 3] [iOS]
我一直在迅速开发应用程序3,
这里有点新(快速编程),
就是这样
我想将数据从第一个表视图控制器中的数组传递给第二个表视图控制器,然后在第二个表视图控制器中,我想使用if函数根据我一直在使用的值在表视图中显示不同的图像在第一个表格视图中
我已经做过segue了,但是没用
这是我的第一个表格视图控制器代码块
var FirstTableArray = [String]()
var SecondArray = [SecondTable]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
FirstTableArray = ["Alam","Sejarah dan Budaya","Buatan"]
SecondArray = [SecondTable(SecondTitle:["11","12","13"]),
SecondTable(SecondTitle:["21","22","23"]),
SecondTable(SecondTitle:["31","32","33"])]
}
“ FirstTableArray”是我想要传递其值的数组,这是第一个表视图控制器中的其他代码段,用于使用“ FirstTableArray”值在表视图中显示标签
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let Cell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CostumTableViewCell
Cell.judulGambar.text = FirstTableArray[indexPath.row]
Cell.namaGambar.image = UIImage(named: gambarMenu[indexPath.row])
Cell.namaGambar.layer.cornerRadius = Cell.namaGambar.frame.size.width/2
Cell.namaGambar.clipsToBounds = true
return Cell
}
现在,我已经成功地使用了“准备segue”方法来传递“ SecondArray”值,但是我无法为“ FirstTableArray”值做到这一点,这是我的segue方法
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var IndexPath : IndexPath = self.tableView.indexPathForSelectedRow!
let DestViewController = segue.destination as! SecondTableViewController
var SecondArrayTableTwo : SecondTable
SecondArrayTableTwo = SecondArray[IndexPath.row]
DestViewController.SecondArray = SecondArrayTableTwo.SecondTitle
}
现在这是我的第二个表视图控制器,我想将第一个表视图控制器数据传递给该视图,我的第二个数组数据已经传递了它的值,但是我无法为我的第二个表视图控制器代码的“ FirstTableArray”值执行此操作
var namaGambarDetail = ["gunungmahawu.jpg","pantaimalalayang.jpg","pulaumanadotua.jpg","pulausuladen.jpg"]
var gambarSejarah = ["pantaimalalayang.jpg","gunungmahawu.jpg","pulaumanadotua.jpg","pulausuladen.jpg"]
var FirstArray = [String]()
var SecondArray = [String]()
override func viewDidLoad() {
super.viewDidLoad()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return SecondArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let Cell = self.tableView.dequeueReusableCell(withIdentifier: "SecondCell", for: indexPath) as! CostumTableViewCell
Cell.judulDetail.text = SecondArray[indexPath.row]
Cell.gambarTampilDetail.image = UIImage(named: namaGambarDetail[indexPath.row])
Cell.gambarTampilDetail.layer.cornerRadius = Cell.gambarTampilDetail.frame.size.width/2
Cell.gambarTampilDetail.clipsToBounds = true
return Cell
}
我想在单击该行时传递“ FirstTableArray”值数据,例如用于选定值的索引路径,以便我可以使用if语句功能在基于第一个视图的单击值基础上更改图像
if(FirstTableArray.text.contains("my first table view array values")){ Cell.gambarTampilDetail.image = UIImage(named: namaGambarDetail[indexPath.row])}
对不起,我的长篇文章,希望你们能理解我的意思,对不起我的英语水平,cmiiw,谢谢,感谢您的帮助:)
从SecondTableViewController删除此行
var SecondArray = [String]()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.