私はこれを可能な限り明確にするつもりです。私のXcodeプロジェクトでは、プロトタイプのセルを再利用しています。それぞれのセルに別のView Controllerを開くようにします。あなたはどうやってそれをすることができると思いますか?ここでテーブルのセルは大きいです
は私のMain.storyboardで再利用可能なセルの写真です:ここで
は再利用されている細胞の結果である:
そしてここにはあります私のコントローラクラスのコード:
import UIKit
class NewsTableViewController: UITableViewController {
@IBOutlet var menuButton:UIBarButtonItem!
@IBOutlet var extraButton:UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
tableView.estimatedRowHeight = 242.0
tableView.rowHeight = UITableViewAutomaticDimension
if revealViewController() != nil {
menuButton.target = revealViewController()
menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
revealViewController().rightViewRevealWidth = 150
extraButton.target = revealViewController()
extraButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// Return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows
return 3
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! NewsTableViewCell
// Configure the cell...
if indexPath.row == 0 {
cell.postImageView.image = UIImage(named: "watchkit-intro")
cell.postTitleLabel.text = "WatchKit Introduction: Building a Simple Guess Game"
} else if indexPath.row == 1 {
cell.postImageView.image = UIImage(named: "custom-segue-featured-1024")
cell.postTitleLabel.text = "Building a Chat App in Swift Using Multipeer Connectivity Framework"
} else {
cell.postImageView.image = UIImage(named: "webkit-featured")
cell.postTitleLabel.text = "A Beginner’s Guide to Animated Custom Segues in iOS 8"
}
return cell
}
}
明確にするために、pic 2の各セルに別のView Controllerを開かせたいと思います。たとえば、セル1で新しいビューコントローラ1を開き、セル2で新しいビューコントローラ2を開き、セル3で新しいビューコントローラ3を開きます。
ありがとう!
UPDATE
私は君たちの一つが示唆されたが、今、私はこれ持って、次のコードを使用しています、セル1をタップしたので、もし私は、3つの新しいクラスを作っ
をセル1のビューコントローラが開き、セル2がタップされている場合は、セル2のビューコントローラが開きます。
明らかにXcodeは私にエラーを与えています。 提案がありますか?ここで
は、読書のための私のMain.storyboard Note that I have entered a class and id for all the new 3 view controllers
おかげで、私はあなたが私に解決策を与えることができることを望みます!
_「表のセルは大きい」_それはどういう意味ですか? –
私が持っている質問は、なぜ各セルが別のビューコントローラを開くようにしたいのですか?それは何かのようなものです、あなたはx種類のビューコントローラを持っていて、いくつかのセルはあるタイプをトリガし、他のタイプは他のタイプをトリガしますか?または、あなたのテーブルビュー内のすべてのセルを別のビューコントローラで開くように計画していますか?これは私に再び尋ねるよう促します:なぜですか? – WERUreo
@WERUreoうん!あなたは正しいことを推測します。彼は、異なるセルをクリックするごとに異なるVCを開くことを望んでいました。しかし、私は彼のUITableViewに50個の細胞があるなら、彼は50個のVCを必要とし、それは良い習慣ではありませんでした。 –