简体   繁体   English

如何将值从一个 Viewcontroller 传递到另一个 struct swift

[英]How to pass value from one Viewcontroller to another struct swift

I'm doing pagination in TableView, for that, I need to pass a value from one ViewController to another struct我正在 TableView 中进行分页,为此,我需要将一个值从一个 ViewController 传递到另一个结构

I'm creating a list of categories in tableview, So the id of each of this Category i need to pass to struct, So that Pagination is done correctly.我正在 tableview 中创建一个类别列表,因此我需要将每个类别的 id 传递给结构,以便正确完成分页。

I get that id of a category, in a ViewController and that Id i need to pass.我在 ViewController 中获得了一个类别的 id,我需要传递这个 id。

For pagination using PagingDataController CocoaPods, previously I was able to pass an id directly(manually) for this CocoaPod, But for now, I'm dynamically passing id.对于使用 PagingDataController CocoaPods 的分页,以前我可以直接(手动)为此 CocoaPod 传递 id,但是现在,我正在动态传递 id。

override func viewDidLoad() {
super.viewDidLoad()
var ida = id } 
}



struct Category: PagingProviderProtocol {
func loadData(parameters: AnyObject?, page: Int, completion: 
@escaping ([Dictionary<String, AnyObject>], Error?) -> Void) {
    var id = Cat_Id
    var cat1 = "category_id="
    var cat2 = cat1+id
     var cx = "https://stagecmsbmncapi.projectpresent.biz/client/article/" + cat2 + "&page=\(page+1)&per_page=\(pageSize)"

    Alamofire.request(cx, method: .get).responseJSON { (response) in
        var error: Error? = response.result.error
        var result: [[String: AnyObject]] = []
        print(response.result.value)
        defer {
            completion(result, error)
        }

        guard let data = (response.result.value as? [String: AnyObject]) else {
            return

        }
        result = data["result"] as! [[String: AnyObject]]
    }

This var ida = id, I'm getting from previous TableView did select method.这个 var ida = id,我是从以前的 TableView 得到的 select 方法。 That id I need to pass to this loadData() inside struct to var id我需要将 id 传递给结构中的这个 loadData() 到 var id

This is the error message " Instance member 'ida' of type 'CatContentsVC' cannot be used on instance of nested type 'CatContentsVC.Category' "这是错误消息“类型'CatContentsVC'的实例成员'ida'不能用于嵌套类型'CatContentsVC.Category'的实例”

Here CatContentsVC is ViewController having a TableView and Category is a struct as defined Below这里 CatContentsVC 是具有 TableView 的 ViewController 和 Category 是如下定义的结构

This is the error message I'm getting, "Instance member 'of type ViewController cannot be used on instance of nested type ViewController"这是我收到的错误消息,“类型 ViewController 的实例成员不能用于嵌套类型 ViewController 的实例”

正如这里提到的,您需要将其添加到您的代码中以使其工作:

otherVC.referanceToOtherViewController = self

暂无
暂无

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

相关问题 如何快速将图像从一个视图控制器传递到另一个视图控制器? - How to pass an image from one viewcontroller to another viewcontroller in swift? 在Swift中将变量从一个ViewController传递给另一个 - Pass variables from one ViewController to another in Swift Swift 3将数据从一个ViewController传递到另一个ViewController - Swift 3 pass data from one ViewController to another ViewController 如何将JSON值从一个ViewController传递到另一个 - How to pass a JSON value from one ViewController to another 如何将文本字段值从一个 ViewController 传递到第二个 ViewController (MacOS Swift)? - How can I pass a textfield value from one ViewController to a second ViewController (MacOS Swift)? 如何仅使用一个ViewController快速将数据从一个UIView传递到另一个UIView? - How to pass data from one UIView to another UIView with using only one ViewController in swift? 将数据从一个视图控制器传递到另一个在 swift 3 中包含 nil - pass data from one viewcontroller to another contains nil in swift 3 以SWIFT语言在Storyboard中将值从一个ViewController传递到另一个 - Passing value from one ViewController to another in Storyboard in SWIFT Language 如何在Swift上从MapView传递解析的PFUser到另一个ViewController? - How to pass (grab) a Parse `PFUser` from `MapView` to another `ViewController` on Swift? 如何将图像和 label 从一个 viewController 传递到 tableViewCell swift? - how to pass image and label from one viewController to tableViewCell swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM