简体   繁体   English

如何使用来自另一个视图控制器的用户输入来使用表视图单元格创建列表

[英]How to make a list with Table View Cells with user input from another view controller swift

I'm making an iOS app with Swift that has two scenes. 我正在用Swift开发一个具有两个场景的iOS应用。 One asks for user input and that is saved in an array. 有人要求用户输入,然后将其保存在数组中。 I'm trying to make a list with table view cells in the other scene, and that list includes the user input that is saved when the user clicks on the save button. 我正在尝试创建一个列表,其中包含另一个场景中的表格视图单元格,并且该列表包括当用户单击“保存”按钮时保存的用户输入。

tried creating a sharedData class in a separate file, tried this: 尝试在单独的文件中创建sharedData类,请尝试以下操作:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "segueTest") {
        var svc = segue!.destinationViewController as! goalViewController
        svc.toPass = textInput
    }
}

(both from other stackoverflow questions) (均来自其他stackoverflow问题)

尝试将数组保存到NSUserDefaults中,然后在新视图中调用保存在NSUserDefaults中的对象。

- Using Delegate is one of the preferred way -使用Delegate是首选方式之一

Example: 例:

protocol PExposeArrayDelegate: class
{
   func getArrayOfItems(array: String)
}


class CustomArray
{

// delegate property to expose array to the view-controller
    internal weak var delegateForTimeLineCell: PExposeArrayDelegate?


internal func createArray()
{
    let arr = ["Vivek","India","Audi"]

     delegateForTimeLineCell.getArrayOfItems(array: arr)
}

}

Now in the class where you want to access the array, do the following: 现在,在要访问数组的类中,执行以下操作:

- Conform to protocol (Delegate) defined above -符合以上定义的protocol (代理)

- Assign self to the delegate -self分配给delegate

- Implement the delegate method and then access the array from inside it. -实现delegate method ,然后从内部访问数组。

Check the example here 在这里查看示例

暂无
暂无

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

相关问题 如何在Swift中从另一个视图访问视图的表格视图的单元格? - How to access cells of a table view of a view from another view in Swift? swift 将带有段的表视图单元格中的数据传递到另一个视图 controller - swift passing data from Table View cells with segment to another view controller 如何在表视图单元格中获取此表视图在Swift 4中另一个表视图控制器中的文本字段文本? - how to get textfields texts in tableview cells that this tableview is in another table view controller in swift 4? 表格视图帮助.....从一个表格视图中选择的单元格迅速传递到另一个表格视图 - Table view Help…..selected cells from one table view passed to another table view swift 如何从另一个视图隐藏容器视图 controller Swift - How to hide container view from another view controller Swift 如何添加额外的表格视图单元格来处理用户输入? - How to add extra table view cells to handle user input? 如何使从视图控制器接收的字符串显示在另一个ViewController的表视图中 - How to make a string received from a view controller show up in a table view in another viewcontroller 将json ID从一个表视图控制器传递到Swift 3中的另一个表视图控制器 - pass json id from one table view controller into another table view controller in swift 3 如何在 Swift 中以编程方式从一个控制器导航到另一个视图控制器? - How to navigate from one controller to another View Controller programmatically in Swift? 如何在Swift 2.0中使用多个View Controller创建动态Table View单元格? - How to create Dynamic Table View cells With multiple View Controller in swift 2.0?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM