【发布时间】:2017-07-06 08:18:13
【问题描述】:
我有这个函数,当用户点击collectionView上的图片时调用。有一个变量url(在print("IMAGE CLICKED:", url) 行中)我想将url 的值发送给另一个viewController 并在url 中设置url。
这是我在firstVC 中未完成的函数。从这里我想将url 发送到secondVC。
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
selectedCommunity = (liveCommunities?[indexPath.row].communityId)!
let home = HomeViewController()
home.showCommunityDetail()
//url is the source for a image in another viewController
//TODO: Send url to other viewController
//There is no relation between the thwo viewControllers (only via tabbar)
print("--------")
print("IMAGE CLICKED:", url)
print("--------")
}
这可能吗?提前感谢您的帮助!
【问题讨论】:
-
这些问题是针对带有 segue 的 viewControllers 的,我没有 segue。
-
Rx 非常棒,因为 github.com/ReactiveX/RxSwift 创建了一个流(Observable)并在创建时将其传递给两个 viewController。然后在其中发布您的网址并在另一个中收听。一开始可能会有点混乱,但值得一看。
标签: ios swift function swift3 uiimage