我有一个链接到标签栏控制器的导航控制器,它链接到一个表视图控制器。
我希望最初使用主题列表打开表格视图。它当前打开了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
}
}
}
答案 0 :(得分: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
}
}