1)、新建兩個UIViewController,通過脫線的形式建立連接。點擊傳遞值得ViewControllrt肉微,按住Ctrl,向被傳遞值的ViewController脫線蜡塌。
2)碉纳、選擇Show Detail。設置一個Identifier馏艾,為ShowGiftDetail
3)劳曹、在collection的點擊事件里面實現(xiàn)傳值
letgiftDetailSegueIdentifier ="ShowGiftDetail"
funccollectionView(collectionView:UICollectionView, didSelectItemAtIndexPath indexPath:NSIndexPath) {
//二級欄目返回時直接變成非選中狀態(tài)
productTag.deselectItemAtIndexPath(indexPath, animated:true)
// segueURL是將要傳遞的值
varsegueURL = ""
if ?let tagList = tags{
segueURL = tagList[indexPath.section].products[indexPath.row].link
}
//按照segue的Identifer進行傳值
self.performSegueWithIdentifier(giftDetailSegueIdentifier, sender: segueURL)
}
overridefuncprepareForSegue(segue:UIStoryboardSegue, sender:AnyObject?) {
//按照segue的Identifier進行辨別
ifsegue.identifier==giftDetailSegueIdentifier{
//創(chuàng)建一個GiftDetailController進行賦值奴愉、傳值
letcontroller = segue.destinationViewControlleras!GiftDetailViewController
controller.giftURL= senderas?String
}
}
4)、如果在DetailViewController中返回到首頁铁孵,只需添加一個Button锭硼,添加一個事件
@IBActionfuncreturnFirstPageController(sender:AnyObject) {
//返回到前一頁
self.presentingViewController?.dismissViewControllerAnimated(true, completion:nil)
}