我一直在開發中迅速3應用程序,
還挺新在這裏(SWIFT編程),
所以這裏的東西,
我想通過數據從第一個表視圖控制器中的數組到第二個表視圖控制器,然後在第二個表視圖控制器中,我想使用if函數根據我在第一個表視圖中使用的值在表視圖中顯示不同的圖像,
我已經做了segue的東西,但它沒有工作
這裏是我的第一個表視圖控制器代碼塊傳遞數組值[SWIFT 3] [iOS版]
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
}
現在我已經成功地通過使用這種用於賽格瑞方法準備「SecondArray」的價值觀,但我不能爲「FirstTableArray」做在這裏值 是我賽格瑞方法
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」值數據的行已被點擊時,像一個indexpath爲選擇的值,所以我可以像這樣
if(FirstTableArray.text.contains("my first table view array values")){ Cell.gambarTampilDetail.image = UIImage(named: namaGambarDetail[indexPath.row])}
抱歉一個if語句功能改變基於在第一視圖點擊值圖像我的長文章,希望你們明白我的意思,對不起我英文不好,cmiiw,謝謝,任何幫助都是ap preciated :)
刪除此行不行的傢伙,不知道爲什麼 –