我试图从firebase仪表板检索用户图像到表格视图单元格。
我已将图像存储在存储中,并将其网址存储在信息中心中:
"UserDevices" : {
"-KRec2mZ5l9Q5QSwiWvS" : {
"Category" : "أخرى",
"Description" : "mmm",
"DeviceName" : "mmm",
"ImageUrl" : "https://firebasestorage.googleapis.com/v0/b/jabeerah-c27c3.appspot.com/o/Devices_Images%2FCF13F154-2B5F-4926-A979-2E187BD0E504.png?alt=media&token=bf1b876f-9f9a-4e78-9e8d-98d017fd0404",
"city" : "Jeddah",
"email" : "testing94@gmal.com",
"name" : "Mariah",
"phone" : "00000"
}
}
此处的代码:
class CategoryDeviceViewController: UITableViewController{
var DeviceNamesArray: NSMutableArray = []
var titlestring: String!
override func viewDidLoad() {
super.viewDidLoad()
// print(globalImageUrl)
self.navigationItem.title = titlestring
let ref = FIRDatabase.database().reference().child("UserDevices")
ref.queryOrderedByChild("Category").queryEqualToValue(titlestring)
.observeEventType(.Value, withBlock: { snapshot in
if let dict = snapshot.value as? NSMutableDictionary{
//print("dict======print \(dict)")
for (key,value) in dict {
let mainDict = NSMutableDictionary()
mainDict.setObject(key, forKey: "userid")
if let dictnew = value as? NSMutableDictionary {
if let metname = dictnew["DeviceName"] as? String
{
mainDict.setObject(metname, forKey: "DeviceName")
}
if let metname = dictnew["Description"] as? String
{
mainDict.setObject(metname, forKey: "Description")
}
if let metname = dictnew["Category"] as? String
{
mainDict.setObject(metname, forKey: "Category")
}
if let metname = dictnew["ImageUrl"] as? String
{
mainDict.setObject(metname, forKey: "ImageUrl")
}
if let metname = dictnew["name"] as? String
{
mainDict.setObject(metname, forKey: "name")
}
if let metname = dictnew["phone"] as? String
{
mainDict.setObject(metname, forKey: "phone")
}
if let metname = dictnew["city"] as? String
{
mainDict.setObject(metname, forKey: "city")
}
if let metname = dictnew["email"] as? String
{
mainDict.setObject(metname, forKey: "email")
}
}
//print("mainDict========= \(mainDict)")
self.DeviceNamesArray.addObject(mainDict)
}
}
self.tableView.reloadData()
})
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
//
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return DeviceNamesArray.count
}
let storageRef = FIRStorage.storage().reference().child("Devices_Images")
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CategotyDeviceCellViewCell
if let name = DeviceNamesArray[indexPath.row] as? NSMutableDictionary {
cell.configureCellone(name["DeviceName"] as! String , Provider: name["name"] as! String , ProviderCity: name["city"] as! String)
let m = name["ImageUrl"]
storageRef.dataWithMaxSize(10 * 1024 * 1024, completion: { (data, error) in
dispatch_async(dispatch_get_main_queue()){
let postPhoto = UIImage(data: data!)
cell.CategoryDeviceImage.image = postPhoto
}
})
}
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
dispatch_async(dispatch_get_main_queue()) { [unowned self] in
let detailsViewController = self.storyboard!.instantiateViewControllerWithIdentifier("DeviceDetailsViewController") as! DeviceDetailsViewController
if let name = self.DeviceNamesArray[indexPath.row] as? NSMutableDictionary{
detailsViewController.self.strUserid = name["userid"] as? String
}
self.navigationController?.pushViewController(detailsViewController, animated: true)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
} //UITableViewController
在cellForRowAtIndexPath
我已经添加了下载图像的功能,但它是从存储中下载图像的!我找不到从firebase文档中的url下载它的功能!
如果我不想指定它的大小,我只想将它作为我在单元格中添加的图像视图的大小!