-
-
Save mosluce/68a9ba23d2771f74eeae11c9b95f39f5 to your computer and use it in GitHub Desktop.
firebase problem2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Firebase | |
class StoreTableViewController: UITableViewController { | |
let flavorSet = NSUserDefaults.standardUserDefaults() | |
let conditionRef = FIRDatabase.database().reference() | |
var stores = [Stores]() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
getFlavorSelectData1() | |
} | |
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 stores.count | |
} | |
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCellWithIdentifier("storeCell", forIndexPath: indexPath) as! StoreTableViewCell | |
cell.storeName.text = stores[indexPath.row].storeName | |
cell.storeAdd.text = stores[indexPath.row].storeAddress | |
cell.storePhone.text = stores[indexPath.row].storePhone | |
cell.storeImage.image = UIImage(named:stores[indexPath.row].storeImage) | |
cell.serviceTime.text = stores[indexPath.row].serviceTime | |
if stores[indexPath.row].isFood == "Y"{ | |
cell.isFood.image = UIImage(named: stores[indexPath.row].isFood) | |
} else if stores[indexPath.row].isDrink == "Y" { | |
cell.isDrink.image = UIImage(named: stores[indexPath.row].isDrink) | |
} else if stores[indexPath.row].isPet == "Y" { | |
cell.isPet.image = UIImage(named: stores[indexPath.row].isPet) | |
} else if stores[indexPath.row].isWifi == "Y" { | |
cell.isWIFI.image = UIImage(named: stores[indexPath.row].isWifi) | |
} | |
//重新整理tableview | |
self.tableView.reloadData() | |
return cell | |
} | |
func getFlavorSelectData1() { | |
//抓取NSUserDefault 1-3 的值 | |
// var n = 1 | |
// for select in 1...3 { | |
// if let select = self.flavorSet.objectForKey("FlavorSelect_\(n)") as? NSNumber{ | |
// n += 1 | |
// } | |
let select = self.flavorSet.objectForKey("FlavorSelect_1") | |
print(select) | |
conditionRef.child("coffee/Products").queryOrderedByChild("flavorID").queryEqualToValue("\(select)").observeEventType(.Value, withBlock:{ snapshot in | |
print ("procuts KEY: \(snapshot.key) . products value: \(snapshot.value)") | |
for child in snapshot.children { | |
let storeID_1 = child.value["storeID"] | |
guard let id_1 = storeID_1 as? String else{ | |
fatalError() | |
} | |
//依照productID取得Store資料 | |
self.conditionRef.child("coffee/Stores").queryOrderedByChild("storeID").queryEqualToValue(id_1).observeEventType(.ChildAdded, withBlock:{ snapshot in | |
print ("stores KEY\(snapshot.key) . Store Value\(snapshot.value)") | |
if let messengerAdd = snapshot.value as? NSDictionary { | |
let getStore = Stores(data: messengerAdd) | |
// //判斷重複store的開關 | |
// var haveSameStore = false | |
// | |
// //判斷重複 | |
// for store in self.stores { | |
// if store.storeID == getStore.storeID { | |
// haveSameStore = true | |
// } | |
// } | |
// //重複為false的時候才把store加到stores array | |
// if !haveSameStore { | |
// self.stores.append(getStore) | |
// }else{ | |
// print("add to array fails") | |
// } | |
self.stores.append(getStore) | |
for a in self.stores{ | |
print("AAAAAA \(a.storeName)") | |
} | |
//重新整理tableview | |
self.tableView.reloadData() | |
}else { | |
print("Please check your Network") | |
} | |
}) | |
} | |
}) | |
} | |
//} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment