Ich habe zwei ViewControllers
. Von meinem ViewController
zu mein EffectsMenuViewController
funktioniert ohne Probleme. Der Code verwende ich für diese ist Aktion ist folgende:Swift - Umschalten zwischen ViewControllern funktioniert nicht
@IBAction func openMenu(sender: AnyObject) {
let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let effectsViewController : EffectsMenuViewContoller = mainStoryboard.instantiateViewControllerWithIdentifier("effectsMenu") as! EffectsMenuViewContoller
presentViewController(effectsViewController, animated: true, completion: nil)
}
Mein presented EffectsMenuViewController
enthält eine UITableView
mit einem benutzerdefinierten TableViewCell
die CategoryRow
genannt wird. Der Code für diese Klasse wie folgt aussieht:
class CategoryRow:UITableViewCell {
@IBOutlet weak var collectionView:UICollectionView!
weak var delegate:CategoryRowDelegate?
}
extension CategoryRow:UICollectionViewDataSource {
/*snipped code */
func collectionView(collectionView: UICollectionView,didSelectItemAtIndexPath indexPath: NSIndexPath) {
ImageObjectSingleton.imageName = DataSource.maskArray.objectAtIndex(indexPath.row) as! String
ImageObjectSingleton.isEyeColorImage = false
ImageObjectSingleton.isMaskImage = true
EffectsMenuViewContoller.callstaticMethod()
} }
In meinem EffectsMenuController
habe ich eine Methode calledstaticMethod
genannt, die durch collectionView(collectionView: UICollectionView,didSelectItemAtIndexPath indexPath: NSIndexPath)
genannt wird:
static func callstaticMethod() {
let c = EffectsMenuViewContoller()
c.didselectItemAtIndexPath()
}
Diese Methode nicht mehr tun, als meine didselectItemAtIndexPath
Methode aufrufen die sollte den aktuellen Viewcontroller entlassen:
func didselectItemAtIndexPath() {
let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let viewController : ViewController = mainStoryboard.instantiateViewControllerWithIdentifier("view") as! ViewController
self.navigationController?.popViewControllerAnimated(true)
self.navigationController?.pushViewController(viewController, animated: true)
self.dismissViewControllerAnimated(true, completion: nil)
}
Wie Sie sehen können, habe ich verschiedene Arten von Code-Anweisungen ausprobiert. Aber keiner von ihnen funktioniert tatsächlich. Allerdings, wenn ich self.dismissViewControllerAnimated(true, completion: nil)
innerhalb einer IBAction
-Methode verwende, funktioniert es, wie ich es wollte, aber ich wirklich wie der Code oben ...
Irgendwelche Ideen? Mit freundlichen Grüßen, Nazar Medeiros
Nun..mein 'ViewController' ist dargestellt und die Methode' self.dismissViewControllerAnimated (true, completion: nil) 'funktioniert sowieso nicht. Es funktioniert nur, wenn ich es innerhalb einer IBAction-Methode verwende. –
Wo wird 'disneyViewControllerAnimated' aufgerufen? Ihr Code ruft diese Methode möglicherweise nicht auf. Es kann helfen, mehr Code in Ihrer Antwort zu posten. – dantheli
ok .. Ich habe meinen Code aktualisiert. Bitte schau es dir an! –