Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何从解析中检索地质点并将其存储在tableView中?_Swift_Uitableview_Parse Platform - Fatal编程技术网

Swift 如何从解析中检索地质点并将其存储在tableView中?

Swift 如何从解析中检索地质点并将其存储在tableView中?,swift,uitableview,parse-platform,Swift,Uitableview,Parse Platform,您好,我有一个应用程序,它将带有名称的地理点存储在解析服务器中,我可以从该服务器将数据检索到控制台,但我无法用它们填充tableView。我怎么能这样做?谢谢 以下是我用来存储数据的代码: let geoPoint = PFObject(className: "location") geoPoint["location"] = activePlace geoPoint["spot"] = places geoPoint.saveInB

您好,我有一个应用程序,它将带有名称的地理点存储在解析服务器中,我可以从该服务器将数据检索到控制台,但我无法用它们填充tableView。我怎么能这样做?谢谢

以下是我用来存储数据的代码:

let geoPoint = PFObject(className: "location")

geoPoint["location"] = activePlace
geoPoint["spot"] = places
geoPoint.saveInBackgroundWithBlock { (succes, error) -> Void in
    print("place has been saved")
}
下面是我用来检索它的代码:

let query = PFQuery(className: "location")
query.findObjectsInBackgroundWithBlock { (object, error) in
   
    
    if error != nil {
        
        print(error)
        
    }else {
        
        print(object)
        self.tableView.reloadData()
        
    }
}
以下是我确定tableView的方式:

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    
    return 1
    
}

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

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
    
    cell.textLabel?.text = places[indexPath.row]["name"]
  
    
    return cell
    
    
    
}
这就是“地点”的确定方式:

var places = [Dictionary<String,String>()]
var places=[Dictionary()]
下面是我在解析服务器上的内容:

谢谢你的帮助

编辑:这是我在控制台中得到的:

Optional([<location: 0x7fd383e34940, objectId: K4E1Dn0qqV, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f2e070>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = place;
        },
                {
            lat = "37.3313521358974";
            lon = "-122.030724242466";
            name = house;
        }
    );
}, <location: 0x7fd383f30600, objectId: D4tdDJcA4x, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f14370>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = place;
        },
                {
            lat = "37.3313521358974";
            lon = "-122.030724242466";
            name = house;
        }
    );
}, <location: 0x7fd383f328c0, objectId: aEyiGvNmze, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f32c00>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = place;
        },
                {
            lat = "37.3313521358974";
            lon = "-122.030724242466";
            name = house;
        }
    );
}, <location: 0x7fd383f32f80, objectId: r9DVe2KJde, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f33320>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = place;
        },
                {
            lat = "37.3313521358974";
            lon = "-122.030724242466";
            name = house;
        }
    );
}, <location: 0x7fd383f336a0, objectId: 9LwM4ATHFC, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f14140>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = place;
        },
                {
            lat = "37.3313521358974";
            lon = "-122.030724242466";
            name = house;
        },
                {
            lat = "37.3246293922446";
            lon = "-122.023606373578";
            name = other;
        }
    );
}, <location: 0x7fd383f33c00, objectId: QM8rg2NKNf, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f34040>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = place;
        },
                {
            lat = "37.3313521358974";
            lon = "-122.030724242466";
            name = house;
        },
                {
            lat = "37.3246293922446";
            lon = "-122.023606373578";
            name = other;
        }
    );
}, <location: 0x7fd383f343c0, objectId: NjlsykJtTf, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f34690>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = "GO to map to add spot";
        }
    );
}, <location: 0x7fd383f34a10, objectId: qdOPtRVzew, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f34c70>";
    location = "-1";
    spot =     (
    );
}, <location: 0x7fd383f34ff0, objectId: DC5ZW7WRNO, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f35250>";
    location = "-1";
    spot =     (
    );
}, <location: 0x7fd383f355d0, objectId: rCZIaHlceC, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f358a0>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = "GO to map to add spot";
        }
    );
}, <location: 0x7fd383f35c20, objectId: 2LI1u9KyNt, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f35ef0>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = "GO to map to add spot";
        }
    );
}, <location: 0x7fd383f36270, objectId: YKd0q9uQcY, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f365b0>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = "GO to map to add spot";
        },
                {
            lat = "37.3263892401666";
            lon = "-122.019776452882";
            name = "new one";
        }
    );
}, <location: 0x7fd383f36930, objectId: rGd3ChyOcV, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f36d60>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = "GO to map to add spot";
        },
                {
            lat = "37.3263892401666";
            lon = "-122.019776452882";
            name = "new one";
        },
                {
            lat = "37.3247014690037";
            lon = "-122.020914298787";
            name = "mc laren";
        }
    );
}, <location: 0x7fd383f37110, objectId: aunhPqs1Ww, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f375a0>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = "GO to map to add spot";
        },
                {
            lat = "37.3263892401666";
            lon = "-122.019776452882";
            name = "new one";
        },
                {
            lat = "37.3247014690037";
            lon = "-122.020914298787";
            name = "mc laren";
        },
                {
            lat = "37.3246335613548";
            lon = "-122.023146659295";
            name = boom;
        }
    );
}, <location: 0x7fd383f37950, objectId: CtWCmwuZHv, localId: (null)> {
    ACL = "<PFACL: 0x7fd383f37c60>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = "GO to map to add spot";
        }
    );
}, <location: 0x7fd383cc37a0, objectId: AHHsEyrCJk, localId: (null)> {
    ACL = "<PFACL: 0x7fd383e228d0>";
    location = "-1";
    spot =     (
                {
            lat = 90;
            lon = 90;
            name = "GO to map to add spot";
        },
                {
            lat = "37.3306871385499";
            lon = "-122.03026490349";
            name = "20405\U201320449 Mariani Ave";
        }
    );
}])
可选([{
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
姓名=地点;
},
{
lat=“37.3313521358974”;
lon=“-122.0307242466”;
姓名=房屋;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
姓名=地点;
},
{
lat=“37.3313521358974”;
lon=“-122.0307242466”;
姓名=房屋;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
姓名=地点;
},
{
lat=“37.3313521358974”;
lon=“-122.0307242466”;
姓名=房屋;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
姓名=地点;
},
{
lat=“37.3313521358974”;
lon=“-122.0307242466”;
姓名=房屋;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
姓名=地点;
},
{
lat=“37.3313521358974”;
lon=“-122.0307242466”;
姓名=房屋;
},
{
lat=“37.32462932446”;
lon=“-122.023606373578”;
名称=其他;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
姓名=地点;
},
{
lat=“37.3313521358974”;
lon=“-122.0307242466”;
姓名=房屋;
},
{
lat=“37.32462932446”;
lon=“-122.023606373578”;
名称=其他;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
name=“转到地图添加点”;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
);
},  {
ACL=“”;
位置=“-1”;
点=(
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
name=“转到地图添加点”;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
name=“转到地图添加点”;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
name=“转到地图添加点”;
},
{
lat=“37.32638940166”;
lon=“-122.019776452882”;
name=“新的”;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
name=“转到地图添加点”;
},
{
lat=“37.32638940166”;
lon=“-122.019776452882”;
name=“新的”;
},
{
lat=“37.3247014690037”;
lon=“-122.020914298787”;
name=“mc laren”;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
name=“转到地图添加点”;
},
{
lat=“37.32638940166”;
lon=“-122.019776452882”;
name=“新的”;
},
{
lat=“37.3247014690037”;
lon=“-122.020914298787”;
name=“mc laren”;
},
{
lat=“37.3246335613548”;
lon=“-122.023146659295”;
名称=动臂;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
name=“转到地图添加点”;
}
);
},  {
ACL=“”;
位置=“-1”;
点=(
{
lat=90;
lon=90;
name=“转到地图添加点”;
},
{
lat=“37.3306871385499”;
lon=“-122.03026490349”;
name=“20405\U201320449马里亚尼大街”;
}
);
}])
编辑2:这是整个tableView代码:

import UIKit
import Parse

var rideSpots = [""]

//test start

class Place {
    var ACL : String
    var location : String
    
    init(ACL : String, location : String) {
        self.ACL = ACL
        self.location = location
    }
}
let places2 : [Place] = []
//test stop

var places = [Dictionary<String,String>()]

var activePlace = -1

class TableViewController: UITableViewController {
    
    @available(iOS 8.0, *)
    func companyNameUpdatedAlert(title: String, error: String, indexPath: Int) {
        
        let alert = UIAlertController(title: title, message: error, preferredStyle: UIAlertControllerStyle.Alert)
        
        alert.addTextFieldWithConfigurationHandler { (textField) -> Void in
            
            textField.placeholder = "Enter new text"
            
        }
        
        alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
            
            let lat = places[indexPath]["lat"]!
            
            let lon = places[indexPath]["lon"]!
            
            places.removeAtIndex(indexPath)
            
            places.insert(["name" : alert.textFields![0].text!, "lat" : lat, "lon" : lon], atIndex: indexPath)
            
            self.tableView.reloadData()
            
            NSUserDefaults.standardUserDefaults().setObject(places, forKey: "places")
            NSUserDefaults.standardUserDefaults().synchronize()
            
            
        }))
        
        self.presentViewController(alert, animated: true, completion: nil)
        
        
    }
    
    @available(iOS 8.0, *)
    override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
        
        let changeText = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Change spot name" , handler: { (action:UITableViewRowAction, indexPath:NSIndexPath) -> Void in
            
            self.companyNameUpdatedAlert("Update text", error: "enter text below", indexPath: indexPath.row)
            
        })
     /*
        let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete" , handler: { (action:UITableViewRowAction, indexPath:NSIndexPath) -> Void in
            
            places.removeAtIndex(indexPath.row)
            
            tableView.reloadData()
            
            NSUserDefaults.standardUserDefaults().setObject(places, forKey: "places")
            NSUserDefaults.standardUserDefaults().synchronize()
 
        })
        */
        return [changeText]
        
        
    }
    
    override func viewDidLoad() {
        
        
            
            super.viewDidLoad()
        
        //retrieve the data from parse start
        
        //first start of test retrieving
        
        let query = PFQuery(className: "location")
        query.findObjectsInBackgroundWithBlock { (objects, error) in
            
            
            if error != nil {
                
                print(error)
                
            }else {
                
                
                
                print(object)
                
                for object in (objects)! {
                    
                    // Retrieve data needed and add to places (example ACL and location)
                    let ACL : String = object["ACL"] as! String
                    let location : String = object["location"] as! String
                    let place : Place = Place(ACL : ACL, location : location)
                    self.places.append(place)
                }
                
                self.tableView.reloadData()
                
            }
        }
        
        
        //end of test retrieving

    /*
        let query = PFQuery(className: "location")
        query.findObjectsInBackgroundWithBlock { (object, error) in
            
            
            if error != nil {
                
                print(error)
                
            }else {
                
                print(object)
                self.tableView.reloadData()
                
            }
        }
    */
    
            //retrieve the data from parse stop
            
            
            if places.count == 1 {
                
                places.removeAtIndex(0)
                
                places.append(["name":"GO to map to add spot","lat":"90","lon":"90"])
                
                
                
                
            }
            if NSUserDefaults.standardUserDefaults().objectForKey("places") != nil {
                
                places = NSUserDefaults.standardUserDefaults().objectForKey("places") as! [Dictionary]
                
                
            }
            
        }
    
    
    override func didReceiveMemoryWarning() {
        
        didReceiveMemoryWarning()
        
    }
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        
        return 1
        
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return places.count
        
        
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
        
        cell.textLabel?.text = places[indexPath.row]["name"]
      
        
        return cell
        
        
        
    }
    
    override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
        
        activePlace = indexPath.row
        
        return indexPath
        
    }
    
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        
        if segue.identifier == "newPlace" {
            
            activePlace = -1
            
            
        }
        
    }
    
    override func viewWillAppear(animated: Bool) {
        
    tableView.reloadData()
        
        
    }

}
导入UIKit
导入解析
var=[“”]
//测试启动
班级{
var-ACL:String
变量位置:字符串
初始化(ACL:String,位置:String){
self.ACL=ACL
self.location=位置
}
}
let places2:[地点]=[]
//测试停止
var places=[Dictionary()]
var activePlace=-1
类TableViewController:UITableViewController{
@可用(iOS 8.0,*)
func companyNameUpdatedAlert(标题:字符串,错误:字符串,索引XPath:Int){
let alert=UIAlertController(标题:标题,消息:错误,首选样式:UIAlertControllerStyle.alert)
alert.addTextFieldWithConfigurationHandle
class Place {
    var ACL : String
    var location : String

    init(ACL : String, location : String) {
        self.ACL = ACL
        self.location = location
    }
}
var places : [Place] = []
let query = PFQuery(className: "location")
query.findObjectsInBackgroundWithBlock { (objects, error) in


    if error != nil {

        print(error)

    }else {

        print(object)

        for object in objects {
            // Retrieve data needed and add to places (example ACL and location)
            let ACL : String = object["ACL"] as String
            let location : String = object["location"] as String
            let place : Place = Place(ACL : ACL, location : location)
            self.places.append(place)
        }

        self.tableView.reloadData()

    }
}