2016-03-08 118 views
0

這是一個非常受歡迎的問題,但在尋找解決方案的兩天中,沒有任何工作。ViewController沒有segue,swift

我有兩個TableView控制器(WeekTableViewController和DiscoverTableViewController),如圖所示,由名爲「discoverWorkouts」顯示的segue鏈接。 DiscoverTableViewController是PFQueryTableViewController的子類。

enter image description here

enter image description here

在添加通常的功能從WeekTableViewController到DiscoverTableViewController,得到以下討厭錯誤到原因請看: 「WeekTableViewController:0x1058469c0>)具有標識符沒有賽格瑞 'discoverWorkouts' '

我有一個在WeekTableViewController中編程式創建的按鈕,這是我的代碼

WeekTableViewController:

override func viewDidLoad() { 
     super.viewDidLoad() 

     //transitionManager = TransitionManager(transitionAnimation: .Fade) 
     //transitioningDelegate = transitionManager 


     self.navigationController?.navigationBarHidden = true //Hide the navigation bar 
     //  tabBarController?.tabBar.hidden = false 
     //  self.hidesBottomBarWhenPushed = true 


     //Add a button to the 
     pingbutton = UIButton(type: UIButtonType.Custom) as UIButton 
     pingbutton.frame = CGRectMake(328, 620, 30, 30) 
     pingbutton.setImage(UIImage(named: "discover"), forState: UIControlState.Normal) 
     pingbutton.addTarget(self, action: "pingButtonTapped:", forControlEvents: UIControlEvents.TouchUpInside) 
     pingbutton.hidden = true 

     self.navigationController?.view.addSubview(ping button) 


.... 

} 

//MARK: Button Tapped 
    func pingButtonTapped(sender:UIButton!) 
    { 
     self.performSegueWithIdentifier("discoverWorkouts", sender:self) 
    } 


    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 

if segue.identifier == "openDiscover" { 

      let discoveryView = segue.destinationViewController as! DiscoverTableViewController 
      discoveryView.transitioningDelegate = self.transitionManager 
     } 

    } 

把一個破發點上的 「self.performSegueWithIdentifier(」 discoverWorkouts 「發件人:個體經營)」 顯示,是在錯誤發生。

我已經試過各種來源:

  • 刪除設備上的應用程序,並重新安裝。
  • 刪除Segue並用不同的名稱再次添加它。
  • 重建兩個tableViewControllers並再次放置segue。

沒有任何工作。

而且在我的應用程序代理,這是WeekTableViewController是如何啓動:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 

     UIApplication.sharedApplication().statusBarStyle = .LightContent 

     //Launch Process 
      let weekView = WeekTableViewController() 
      self.landingNavigationController = UINavigationController(rootViewController: weekView) 
      self.landingNavigationController?.navigationBar.barTintColor = UIColor.blackColor() 
      self.landingNavigationController?.navigationBarHidden = true 

      self.window?.tintColor = UIColor.blackColor() //(red: 0.0, green: 1.0, blue: 30.0/255.0, alpha: 1.0) 
      self.window?.rootViewController = self.landingNavigationController 
//   self.window?.rootViewController = tabBarNavController 
      self.window?.makeKeyAndVisible() 


} 

在世界上什麼可能會發生的任何想法。謝謝。 :)

回答

1

如果您想使用它的功能,您必須從故事板中實例化您的ViewController

因此,而不是創建ViewController s ^自己,你應該做這樣的事情:

let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil) 
self.landingNavigationController = storyboard.instantiateInitialViewController() as! UINavigationController 
// additional setup (optional) 
self.window?.rootViewController = self.landingNavigationController 
self.window?.makeKeyAndVisible() 

這將創建初始ViewController(可能是UINavigationController),因爲它在你的故事板的已配置。

+0

非常感謝。它在一個微小的週期內工作。我意識到我的WeekTableViewController沒有導航控制器,所以我在其中嵌入了一個,並且您的建議全部解決。 )。 – Gugulethu