我有一个名为Beacon Array的数组,它存储信标信息,数组类型为AnyObject。我有另一个数组存储这样的名字。
这些数字应与我在第一个数组中保存的信标小调相匹配。因此,在我的表格视图中,我可以按距离顺序在列表中显示名称。
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate, UITableViewDelegate,UITableViewDataSource{
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var refresh: UIBarButtonItem!
let locationManager = CLLocationManager()
let region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: "74278BDA-B644-4520-8F0C-720EAF059935")!, identifier: "Beacon1")
let name = [
513: "Max",
65505: "Juan",
512: "Jack"
]
var size = 0
var beaconArray = []
var timer = NSTimer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationManager.delegate = self
if(CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedWhenInUse){
locationManager.requestWhenInUseAuthorization()
}
locationManager.startRangingBeaconsInRegion(region)
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.delegate = self;
tableView.dataSource = self;
//self.timer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: ("testing"), userInfo: nil, repeats: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.name.count
//return self.beaconArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
if self.beaconArray.count > 0 {
let minor = self.beaconArray[indexPath.row].minor
println(minor)
}
//cell.textLabel?.text = "\(minor)"//self.name[self.beaconArray[indexPath.row].minor] //[indexPath.row]
//cell.textLabel?.text = self.name[indexPath.row]
return cell
}
/* func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
println("You selected cell #\(indexPath.row)!")
}*/
func locationManager(manager: CLLocationManager!, didRangeBeacons beacons: [AnyObject]!, inRegion region: CLBeaconRegion!) {
//print(beacons)
self.beaconArray = [AnyObject](beacons)
// self.beaconArray.sortedArrayUsingComparator()
/* for beacon in beaconArray {
println("ID: \(beacon.minor) Accuracy: \(beacon.accuracy), RSSI: \(beacon.rssi)")
}
println("-------RESULT END---------------")
self.size = beaconArray.count
*/
//println("Size: \(self.size)")
}
}
答案 0 :(得分:0)
好的,现在我看到了很多需要在代码中完成的修复。首先应将var beaconArray : [CLBeacon] = []
类型声明为CLBeacon
beaconArray
其次关于numberOfRowsInSection返回func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.beaconArray.count
}
计数。这样,您将确保仅在获取信标后填充列表
beaconArray
最后获取信标后将它们放入func locationManager(manager: CLLocationManager!, didRangeBeacons beacons: [AnyObject]!, inRegion region: CLBeaconRegion!) {
//print(beacons)
self.beaconArray = beacons as! [CLBeacon]
self.tableView.reloadData()
}
并重新加载表格视图数据
$(document).ready(function(){
$(".contactButton").on("click", function(){
$user = this.value;
$.ajax({
url: "insert_announcements.php",
type: "POST",
data: "userid="+$('#userid').val()+"&msg="+$('#announcement_message').val(), ,
success: function(text){
if(text == "Error!"){
alert("Unable to get user info!");
$(".announcement_success").fadeIn();
$(".announcement_success").show();
$('.announcement_success').html('Payment Status Changed!');
$('.announcement_success').delay(5000).fadeOut(400);
alert(data);
} else {
var txtArr = text.split('|');
}
},
error: function(xhr, textStatus, errorThrown){
alert(textStatus + "|" + errorThrown);
}
});
});
});