【问题标题】:(swift)initial view controller call tableview controller without hitting any button(swift) 初始视图控制器调用 tableview 控制器而不点击任何按钮
【发布时间】:2016-05-24 11:05:12
【问题描述】:

我已尝试使用以下代码执行此操作。但是,它不起作用。

警告:尝试呈现不在窗口层次结构中的视图!

有什么方法可以在不点击按钮的情况下调用其他视图控制器?

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let configuration = WKWebViewConfiguration()
    let controller  =  WKUserContentController()
    controller.addScriptMessageHandler(self, name: "JSListener")
    configuration.userContentController = controller

    let webview = WKWebView(frame: self.view.frame, configuration: configuration)
    let url = NSBundle.mainBundle().URLForResource("index1", withExtension: "html")
    let request = NSURLRequest(URL: url!)

    self.view = webview
    webview.loadRequest(request)

     let secondViewController:UIViewController = OurTableViewController()
    self.presentViewController(secondViewController, animated: true, completion: nil)
}

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    尝试移动

    let secondViewController:UIViewController = OurTableViewController()
    self.presentViewController(secondViewController, animated: true, completion: nil)
    

    像那样查看DidAppear

    override func viewDidAppear(animated: Bool) {
        let secondViewController:UIViewController = OurTableViewController()
        self.presentViewController(secondViewController, animated: true, completion: nil)
    }
    

    【讨论】:

    • 一些错误抛出。 ableView 教程[12959:283655] *** 断言失败 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITableView.m:6573 2016-05-24 11:14:53.402 TableView 教程 [12959:283655] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法使具有标识符 ourCell 的单元格出列 - 必须为标识符或连接故事板中的原型单元'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多