セルを別のビューに移動するように設定する方法を見つけようとしています。この場合、グループをリストしていますログイン後、ユーザーが好きなサービスをタップすると、それらはマップに移動します。しかし、タップしたときに地図に表示されるようにセルを設定する方法はわかりません。私はセグを作成しようとしましたが、セルがタップされても何も起こりません。私はプログラミングが初めてで、誰かがこれを説明できるかどうか疑問に思っていました。私は、セルをXcode 9の別のビューコントローラに移動する方法を知りました。
私はセル(基本的なもの)を設定する方法の理解を私に与えたYouTubeビデオの束を見ました。
本当にありがとうございます、ありがとうございました!
この投稿は、プログラミングの旅に足を浸している人を支援します。
ありがとう、幸せなコーディング!ここで
は、私が現在持っているコードです:
import UIKit
struct cellData {
let cell : Int!
let text : String!
let image : UIImage! }
class ListServicesTVC: UITableViewController {
var arrayOfCellData = [cellData]()
override func viewDidLoad() {
arrayOfCellData = [cellData(cell : 1, text : "Barber Services", image : #imageLiteral(resourceName: "barberservice")),
cellData(cell : 2, text : "Salon Services", image : #imageLiteral(resourceName: "salonservice"))]
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrayOfCellData.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if arrayOfCellData[indexPath.row].cell == 1 {
let cell = Bundle.main.loadNibNamed("BarberServiceCell", owner: self, options: nil)?.first as! BarberServiceCell
cell.barberImageView.image = arrayOfCellData[indexPath.row].image
cell.barberServicesLabel.text = arrayOfCellData[indexPath.row].text
return cell
}
else if arrayOfCellData[indexPath.row].cell == 2 {
let cell = Bundle.main.loadNibNamed("SalonServicesCell", owner: self, options: nil)?.first as! SalonServicesCell
cell.salonImageView.image = arrayOfCellData[indexPath.row].image
cell.salonServicesLabel.text = arrayOfCellData[indexPath.row].text
return cell
}
else {
let cell = Bundle.main.loadNibNamed("BarberServiceCell", owner: self, options: nil)?.first as! BarberServiceCell
cell.barberImageView.image = arrayOfCellData[indexPath.row].image
cell.barberServicesLabel.text = arrayOfCellData[indexPath.row].text
return cell
}
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if arrayOfCellData[indexPath.row].cell == 1 {
return 120
}
else if arrayOfCellData[indexPath.row].cell == 2 {
return 120
}
else {
return 120
}
}
}
'cell = Bundle.main.loadNibNamed(" BarberServiceCell "、owner:self、options:nil)と書かないでください。 BarberServiceCell'。それは細胞の「再使用」を避けます。代わりに 'tableView.dequeueCell ...'を使います。タップを検出するには、 'UITableViewDelegate'メソッド' didSelect: 'を実装する必要があります – Larme
*セル*(ビュー)を別のビューに移動して*データソース項目*(モデル) – vadian
フルラインコードの外観 – Adeel