【问题标题】:how to initially open a table view to a selected detail view in swift如何在swift中最初打开一个表视图到选定的详细视图
【发布时间】:2015-07-10 21:54:33
【问题描述】:

我有一个导航控制器链接到一个标签栏控制器,该控制器链接到一个表格视图控制器。

我希望最初打开带有主题列表的表格视图。它当前在 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
        }
    }
}

【问题讨论】:

  • 是的。在显示表格视图之前,您可以将详细视图控制器推入堆栈。
  • 很抱歉,当我从标签栏控制器打开它时,我不明白该怎么做,也不知道如何为视图指定初始文件。
  • 那么您的视图最初是如何设置的?一些代码会很好。
  • 这是主控制器中的代码:
  • 把它放在你的问题中

标签: ios swift


【解决方案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
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    相关资源
    最近更新 更多