[英]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.