SWRevealViewController:从同一ViewController中的不同URL获取内容

时间:2015-03-05 05:35:59

标签: ios swift uiviewcontroller menu navigation

我正在尝试制作一个博客阅读器应用程序,其中包含侧面导航菜单/滑出菜单中列出的博客类别。我正在关注这个tutorial。本教程将所有菜单项静态链接到各自的ViewControllers。

我希望我的所有类别都只能在NewsTableViewController中打开,因为重复新闻控制器会是一个非常糟糕的主意。

我对NewsTableViewController的当前viewDidLoad方法是:

 override func viewDidLoad() {
    super.viewDidLoad()

    if self.revealViewController() != nil {
        menuButton.target = self.revealViewController()
        menuButton.action = "revealToggle:"
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    }

    categoryUrl = NSURL(string: "http://www.techmuzz.com/news/api/get_recent_posts/")!

    var request: NSURLRequest = NSURLRequest(URL: categoryUrl!)
    tableView.hidden = true

    let session = NSURLSession.sharedSession()
    let task = session.dataTaskWithURL(categoryUrl!, completionHandler: {data, response, error -> Void in
        //   println("Task completed")
        if(error != nil) {
            // If there is an error in the web request, print it to the console
            println(error.localizedDescription)
        }
        var err: NSError?

        var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
        if(err != nil) {
            // If there is an error parsing JSON, print it to the console
            println("JSON Error \(err!.localizedDescription)")
        }
        let results: NSArray = jsonResult["posts"] as NSArray
        self.didReceiveResults(jsonResult)


    })
    task.resume()
}

这会加载NewsTableViewController中的最新帖子。现在,还有另一个类别,例如,新闻,其中包含在侧面导航菜单中添加的网址http://www.techmuzz.com/api/get_recent_posts/?json=get_category_posts&slug=news-2。我如何传递它的url,以便它被加载到相同的NewsTableViewController中。

有人可以帮我弄清楚如何做到这一点。我提前谢谢你

0 个答案:

没有答案
相关问题