简体   繁体   English

如何快速以编程方式打开新的表格视图

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

I created a tableview in storyboard that contains 11 rows. 我在情节提要中创建了一个包含11行的表格视图。 I want to be able to tap on each row and have it open up into it's own tableview controller, where I will store data, depending on the row tapped. 我希望能够点击每一行并将其打开到自己的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
}

This is what I have done to create the rows. 这就是我创建行所要做的。

In short: 简而言之:

  1. Go to your Storyboard 转到您的情节提要
  2. Add another TableViewController to the Storyboard 将另一个TableViewController添加到情节提要
  3. Press and hold the right mouse button on the tableViewCell of the TableView with 11 rows and drag it towards the newly created TableViewController 按住具有11行的TableView的tableViewCell上的鼠标右键,并将其拖到新创建的TableViewController上
  4. Release the mouse and a popup will appear. 释放鼠标,将出现一个弹出窗口。
  5. Choose one of the items eg show 选择其中一项,例如show
  6. Build and run your app, click on a cell and a new TableViewController will open 生成并运行您的应用程序,单击一个单元格,然后将打开一个新的TableViewController

To send data to the ViewController that's been shown by clicking a row, you should look into the method prepareForSegue(_) 要将数据发送到单击行已显示的ViewController,应查看方法prepareForSegue(_)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Swift中打开search tableView - How to open the search tableView in Swift 迅速单击表格视图单元格,打开一个新的TabBarController - Open a new TabBarController on clicking a tableview cell in swift 如何在Swift中以编程方式创建带有节的Grouped TableView - How to create a Grouped TableView with sections programmatically in Swift 如何以编程方式打开url但无法在浏览器中快速打开 - How to open url programmatically but not open in browser swift 在tableView Swift中选择textField时打开New ViewController - Open New ViewController when textField is selected in tableView Swift 如何在TableView中快速设置新对象? - How to set the new object in TableView, swift? 如何从用户选择表视图中的行快速显示新的表视图 - how to display a new tableview from user selecting row in tableview swift 如何以编程方式将不同单元格的不同图像添加到tableView(Swift 3) - How to add different images for different cell to a tableView programmatically (Swift 3) 如何以编程方式隐藏或删除TableView Swift 2.2中的多余单元格和分隔符 - how to programmatically hide or delete extra cell and seperators in tableview swift 2.2 如何以编程方式将不同单元格的不同图像添加到tableView(Swift) - How to add different images for different cell to a tableView programmatically (Swift)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM