2015-07-10 81 views
1

我有一個導航控制器鏈接到標籤欄控制器鏈接到表視圖控制器。如何最初打開表格視圖到swift中選定的詳細視圖

我想要表格視圖最初打開主題列表。它目前在Table View Controller的詳細視圖中打開。

有沒有辦法做到這一點?使用Swift和Xcode。 下面是主控制器代碼:

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    //self.navigationItem.leftBarButtonItem = self.editButtonItem()let path = NSBundle.mainBundle().pathForResource("TopicList", ofType: "plist")! 
    let topicsDict = NSDictionary(contentsOfFile: path)! 
    topics = topicsDict["topics"]! as! [NSDictionary] as! [[String: String]] 
    keys = topicsDict.allKeys as! [String] 

    //let addButton = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "insertNewObject:") 
    //self.navigationItem.rightBarButtonItem = addButton 
    if let split = self.splitViewController { 
     self.detailViewController = split.viewControllers.last as? DetailViewController 
    } 
} 


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    if segue.identifier == "showDetail" { 
     if let indexPath = tableView.indexPathForSelectedRow(){ 
      let object = topics[indexPath.row] 
      let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController 
      controller.detailItem = object 
      controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem() 
      controller.navigationItem.leftItemsSupplementBackButton = true 
     } 
    } 
} 
+1

是有。在顯示錶格視圖之前,您可以將詳細視圖控制器推入堆棧。 – rocky

+0

我很抱歉,但我不明白如何做到這一點,當我從標籤欄控制器打開它,也不知道如何指定視圖的初始文件。 – rlowensohn

+0

那麼您的觀點最初是如何設置的?一些代碼會很好。 – rocky

回答

1

我沒有迴應,但我並加入一個選項,在主控制器代碼的初始視圖解決的問題:

func configureView() { 
    // Update the user interface for the detail item. 
    if let detail: AnyObject = self.detailItem { 
     if let label = self.detailDescriptionLabel { 
      let dict = detail as! [String: String] 
      let urlString = dict["url"]! 

      let pdfLoc = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(urlString, ofType: "pdf")!) 
      let request = NSURLRequest(URL: pdfLoc!) 
      webView.loadRequest(request) 


      let topic = dict["title"]! 

      title = "" 
      label.text = topic 

      let bottomOffString = dict["bottom"]! 
      if bottomOffString == "1" { 
       buttonSwitch.enabled = false 
       buttonSwitch.hidden = true 
      } else { 
       buttonSwitch.setTitle("Details =>", forState: UIControlState.Normal) 
      } 
     } 
    } else { 
     let urlString = "Quick Tips" 
     let pdfLoc = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(urlString, ofType: "pdf")!) 
     let request = NSURLRequest(URL: pdfLoc!) 
     webView.loadRequest(request) 

     title = "Quick Tips" 
     //label.text = "Quick Tips" 
     buttonSwitch.enabled = false 
     buttonSwitch.hidden = true 
    } 
} 
相關問題