0
我試圖排序創建查詢像奕犛牛在那裏我可以在某個位置內看到消息的查詢,但每當我發佈一條消息,結果不顯示在查詢中的數據。我基本上想要我發送的消息顯示在查詢中。我想我在代碼中正確地完成了我的邏輯,但是我錯過了可以在查詢中顯示數據的內容。上週我一直在處理這個問題,只是這個修復可能會結束我的項目的這一部分。誰能幫我這個?每節我應該返回多少行?
import UIKit
import ParseUI
import Parse
import CoreLocation
@available(iOS 8.0, *)
class HomeViewController: PFQueryTableViewController,CLLocationManagerDelegate {
var messages = [String]()
var users = [String: String]()
let bubbleFeeds = [
("1"),
("2"),
("I3"),
("4"),
("5"),
("6") ]
let locationManager = CLLocationManager()
var currLocation : CLLocationCoordinate2D?
override init(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.parseClassName = "BubbleTest"
self.textKey = "textField"
self.pullToRefreshEnabled = true
self.objectsPerPage = 200
}
private func alert(message : String) {
let alert = UIAlertController(title: "Oops something went wrong.", message: message, preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)
let cancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil)
let settings = UIAlertAction(title: "Settings", style: UIAlertActionStyle.Default) { (action) -> Void in
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
return
}
alert.addAction(settings)
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.estimatedRowHeight = 60
self.tableView.rowHeight = UITableViewAutomaticDimension
locationManager.desiredAccuracy = 1000
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
alert("Cannot fetch your location")
}
func queryForTable() -> PFQuery! {
let query = PFQuery(className: "BubbleTest")
if let queryLoc = currLocation {
query.whereKey("location", nearGeoPoint: PFGeoPoint(latitude: queryLoc.latitude, longitude: queryLoc.longitude), withinMiles: 10)
query.limit = 200;
query.orderByDescending("createdAt")
} else {
/* Decide on how the application should react if there is no location available */
query.whereKey("location", nearGeoPoint: PFGeoPoint(latitude: 37.411822, longitude: -121.941125), withinMiles: 10)
query.limit = 200;
query.orderByDescending("createdAt")
}
return query
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
locationManager.stopUpdatingLocation()
if(locations.count > 0){
let location = locations[0]
print(location.coordinate)
currLocation = location.coordinate
} else {
alert("Cannot receive your location")
}
}
override func objectAtIndexPath(indexPath: NSIndexPath!) -> PFObject! {
var obj : PFObject? = nil
if(indexPath.row < self.objects!.count){
obj = self.objects![indexPath.row] as! PFObject
}
return obj
}
// override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//
//
// 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 users.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("object", forIndexPath: indexPath) as! Bubbles
let object = PFObject(className: "BubbleTest")
cell.name.text = object.valueForKey ("userName") as? String
cell.message.text = object.valueForKey("textField") as? String
cell.dateTime.text = "\((indexPath.row + 1) * 3)m ago"
cell.message.numberOfLines = 0
let score = object.valueForKey("count") as! Int
cell.likeCount.text = "\(score)"
let replycnt = object.valueForKey("replies") as! Int
cell.responseCount.text = "\(replycnt) replies"
//cell.userImage.image = PFUser.currentUser()?.valueForKey("photo") as! PFFile
// Configure the cell...
return cell
}
@IBAction func likeButton(sender: AnyObject) {
let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
let object = objectAtIndexPath(hitIndex)
object.incrementKey("count")
object.saveInBackground()
self.tableView.reloadData()
NSLog("Top Index Path \(hitIndex?.row)")
}
是什麼意思是用戶指南?此外,我已將段中的行數恢復爲零,但仍然看到空行和行,並且查詢中沒有顯示任何數據。 – JoshyBroheme
解析提供了許多與其API和SDK相關的用戶指南,它們涵蓋定製和使用他們的表格視圖控制器。拿出你所有的代碼,更改的行數,並得到一個基本的表格第一工作使用超邏輯,然後從那裏定製... – Wain
我查PFTableViewControllers用戶指南,它幾乎證實它不需要的cellForRowAtIndexPath。所以我創建了一個新文件並添加了我的代碼,這次沒有行計數,但我無法看到查詢中顯示的數據。我不確定我是否正確地說了些什麼,但還有什麼需要做的? – JoshyBroheme