如何在我的所有场景中使SWRevealViewController可用?

时间:2016-04-07 09:51:18

标签: swift xcode7 swrevealviewcontroller

我正在使用swift在Xcode7上创建一个应用程序,我真的需要一些帮助。我想让SWRevealViewController侧边栏出现在我的所有场景中,但问题是它只出现在第一个视图控制器上,我将push segue设置为显示。点击边栏上的链接,导航栏会在下一个场景中消失?请有人帮忙......

sidebar

enter image description here

这是我在UITableViewController上用于侧边栏链接的脚本

var catArrayId = [String]()
var catArrayName = [String]()
var catArrayImg2 = [String]()

override func viewDidLoad(){

    // get available categories according to customer country
    get_categories()

}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return catArrayId.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("navCell", forIndexPath: indexPath) as UITableViewCell
    cell.textLabel?.text = self.catArrayName[indexPath.row]
    return cell
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.performSegueWithIdentifier("showCategory", sender: self)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showCategory" {
        let VC = segue.destinationViewController as! CategoryProductsViewController

        let indexPath: NSIndexPath = self.tableView.indexPathForSelectedRow!
        let categoryImage = UIImage(named: catArrayImg2[indexPath.row])

        VC.catId = self.catArrayId[indexPath.row]
        VC.image = categoryImage!

    }
}

func get_categories(){
    let country_id = 168
    //let startTime = NSDate.timeIntervalSinceReferenceDate()
    let pageUrl = "https://domain.com/ios/home-categories-image.php?country_id=\(country_id)&uudi=" + NSUUID().UUIDString
    let myUrl = NSURL(string: pageUrl)
    let request = NSMutableURLRequest(URL: myUrl!)
    request.HTTPMethod = "GET"
    request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData

    let session = NSURLSession.sharedSession()
    let task = session.dataTaskWithRequest(request){
        (let data, let response, let error) in

        if(error != nil){
            print(error?.localizedDescription)
            return
        }

        do{
            let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .AllowFragments)
            let catArray = json as? [[String: AnyObject]]
            for catArr in catArray!{

                let catName = catArr["name"] as? String
                let catID = catArr["id"] as? String
                let img2 = catArr["image2"] as? String

                dispatch_async(dispatch_get_main_queue(), {
                    self.catArrayId.append(catID!)
                    self.catArrayName.append(catName!)
                    self.catArrayImg2.append(img2!)
                    self.tableView.reloadData()
                })
            }
        }
        catch{
            print("Error serializing JSON: \(error)")
        }
    }
    task.resume()
}

0 个答案:

没有答案