我正在使用swift在xcode7上创建一个应用程序,我真的需要一些帮助。我想让swrevealviewcontroller侧边栏出现在我的所有场景中,但问题是它只出现在我将push segue设置为show的第一个视图控制器上。同时点击侧边栏上的链接,导航栏会在下一个场景中消失?请有人帮忙…
sidebar
swift - 如何使SWRevealViewController在我的所有场景中可用?-LMLPHP
这是我在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()
}

最佳答案

如果我正确理解了您的问题,那么您可以按照controller的作者提供的示例(“revealcontrollerstoryboardexample2”)来执行相同的操作。当您从Rear VC中选择某个对象时,该操作的segue需要具有类“swrevealviewcontrollerseguepuscontroller”。以下是此示例的屏幕截图:swift - 如何使SWRevealViewController在我的所有场景中可用?-LMLPHP

关于swift - 如何使SWRevealViewController在我的所有场景中可用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36472551/

10-12 01:50