gpt4 book ai didi

ios - 如何快速打开 TableView 到选定的详细 View

转载 作者:行者123 更新时间:2023-11-28 07:03:47 25 4
gpt4 key购买 nike

我有一个导航 Controller 链接到一个标签栏 Controller ,标签栏 Controller 链接到一个 TableView Controller 。

我希望首先打开带有主题列表的 TableView 。它当前在 TableView Controller 的详细 View 中打开。

有没有办法做到这一点?使用 Swift 和 Xcode。这是主 Controller 中的代码:

    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
}
}
}

最佳答案

我没有得到任何回应,但我确实通过在主 Controller 代码中为初始 View 添加一个选项解决了这个问题:

    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
}
}

关于ios - 如何快速打开 TableView 到选定的详细 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31350902/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com