快速移动Page的困难

时间:2016-04-13 13:44:33

标签: swift navigation

当我选择UIButoon(selectMaghsad或selectMabda)时,飞机搜索到选择城市没有困难和问题我在selecteCity中选择一个单元格(tableviewController)返回AircraftSearch并在标签中显示数据(labelcity)问题是如果没有我想再次转到tableViewController(selecteCity)

并提醒:

A
Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x7f867b5a4920 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "(null)"}}

为什么? 你认为问题在哪里? 你能救我吗?

  

AircraftSearch

class AircraftSearch: UIViewController ,SendbackDelegate{

@IBOutlet weak var Mabda: UIButton!
@IBOutlet weak var maghsad: UIButton!
@IBOutlet weak var labelcity: UILabel!

@IBOutlet weak var cityTectfield: UITextField!

var Airurl = NSURL()
var ScrOrDstArray = [MabdaAndMaghsad]()
var origin = [String]() // save mabda
var purpose = [String]() // save maghsad
var sendDataToTableview = [String]()
var tit = String()




override func viewDidLoad() {
    super.viewDidLoad()


    labelcity.text  = tit
    GetPassCity()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func selectMabda(sender: AnyObject) {
    sendDataToTableview = origin
    performSegueWithIdentifier("SelectedCellSegue", sender: sender)


}

@IBAction func selectMaghsad(sender: AnyObject) {
    sendDataToTableview = purpose
    print(sendDataToTableview)
    performSegueWithIdentifier("SelectedCellSegue", sender: sender)

}


func originAndpurpose() {
    let dataCity = ScrOrDstArray
    for i in dataCity{

        if i.SrcOrDst == true{
            origin.append(i.Name)
        }else{
            purpose.append(i.Name)
        }
    }
}



func GetPassCity(){
    let actInd : UIActivityIndicatorView        = UIActivityIndicatorView(frame: CGRectMake(0,0, 50, 50)) as UIActivityIndicatorView
    actInd.center                           = self.view.center
    actInd.hidesWhenStopped                 = true
    actInd.activityIndicatorViewStyle       = UIActivityIndicatorViewStyle.Gray
    view.addSubview(actInd)
    actInd.startAnimating()


    NSURLSession.sharedSession().dataTaskWithURL(Airurl){ ( data ,response ,error) in
        if error != nil{
            print("A")
            print(error!)
        }else{

            do{
                //readin data from Server
                let posts   = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! [[String:AnyObject]]
                //save data
                for post in posts{
                    var postCity:MabdaAndMaghsad?
                    if  let  Id         = post["Id"]        as? Int     ,
                        let nameCity    = post["Name"]      as? String  ,
                        let SrcOrDst    = post["SrcOrDst"]  as? Bool
                    {
                        postCity    = MabdaAndMaghsad(ID: Id, Name: nameCity, SrcOrDst: SrcOrDst)
                    }
                    self.ScrOrDstArray.append(postCity!)

                }

                //===============

                dispatch_async(dispatch_get_main_queue()){
                    actInd.stopAnimating()
                    self.originAndpurpose()
                   print(self.origin)
                    print("=======")
                 //   print(self.purpose)
                }

            }catch let error as NSError{

                print("B")
                print(error)
            }
        }


        }.resume()

}


func sendNameToPreviousVC(SelectCity: String) {
    tit = SelectCity

}


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

            VC.toTake = sendDataToTableview
            VC.delegate = self
        }
    }

}

}

  

SelectedCity视图

import UIKit
protocol SendbackDelegate:class {
    func sendNameToPreviousVC(City:String)
}

class SelectedCity: UITableViewController {
    var toTake = [String]()
    var selecteCity = String()
    weak var delegate: SendbackDelegate? = nil

    override func viewDidLoad() {
        super.viewDidLoad()


    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        navigationController?.setNavigationBarHidden(false, animated: true)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source


    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return toTake.count ?? 0

    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("stcell", forIndexPath: indexPath) as? mAndMCell

        let nameCity = toTake[indexPath.row]
        print(nameCity)

        cell!.nameCityLabel.text = nameCity
        return cell!
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){

        let indexPath = tableView.indexPathForSelectedRow!
        let currentCell = tableView.cellForRowAtIndexPath(indexPath) as! mAndMCell!

        selecteCity = currentCell.nameCityLabel!.text as String!

        sendBackIdCity(selecteCity)
        navigationController?.popViewControllerAnimated(true)



    }
    func sendBackIdCity(name: String){
        self.delegate?.sendNameToPreviousVC(name)

    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "backCitySegue"{
            var VCOne = segue.destinationViewController as? AircraftSearch
            self.delegate = VCOne


        }
    }

}

pic

0 个答案:

没有答案