簡體   English   中英

如何快速以編程方式打開新的表格視圖

[英]How to open up a new tableview programmatically in swift

我在情節提要中創建了一個包含11行的表格視圖。 我希望能夠點擊每一行並將其打開到自己的tableview控制器中,根據所點擊的行,我將在其中存儲數據。

      var array = ["row 1", "row 2", "row 3", "row 4", "row 5", "row 6", "row 7", "row 8", "row 9", "row 10", "row 11"]

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return array.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("prototypeCellIdentifier", forIndexPath: indexPath)
        cell.textLabel?.text = array[indexPath.item]
        cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator 
    return cell
}

這就是我創建行所要做的。

簡而言之:

  1. 轉到您的情節提要
  2. 將另一個TableViewController添加到情節提要
  3. 按住具有11行的TableView的tableViewCell上的鼠標右鍵,並將其拖到新創建的TableViewController上
  4. 釋放鼠標,將出現一個彈出窗口。
  5. 選擇其中一項,例如show
  6. 生成並運行您的應用程序,單擊一個單元格,然后將打開一個新的TableViewController

要將數據發送到單擊行已顯示的ViewController,應查看方法prepareForSegue(_)

暫無
暫無

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

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