func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
let vc = storyboard?.instantiateViewController(withIdentifier: "vc1")as? DetailViewController
//vc?.image = img[indexPath.row]!
//vc?.name = imageArray[indexPath.row] storyboard
self.navigationController?.pushViewController(vc!, animated: true)
}
错误是:
使用未解析的标识符“ storyboard”
答案 0 :(得分:0)
看看这个:
// Case: When the next ViewController is existed in the same Storyboard.
let controller = self.storyboard?.instantiateViewController(withIdentifier: "ControllerIdentifier") as! YourViewController
// pass data here to the next controller.
self.navigationController?.pushViewController(controller, animated: true)
// Case: When the next ViewController is exists in other Storyboard.
let storyboard = UIStoryboard(name: "StoryboardName", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "ControllerIdentifier") as! YourViewController
// pass data here to the next controller.
self.navigationController?.pushViewController(controller, animated: true)
注意:当您使用'withIdentifier:“ vc1”'这行时,我建议您始终为与ViewController的类名相同的ViewController分配情节提要ID。养成习惯,这将很有帮助,因为您无需记住设置的情节提要ID。因此,保持简单。
答案 1 :(得分:-1)