いつもお世話になっております。
Firebaseで取得したNSDictionary型データを、
TableViewに表示させたいのですが、
ビルドエラーが発生いたします。
「Could not cast value of type '__NSCFString' (0x1b4ead5e8) to 'NSDictionary' (0x1b4eae768).」
*Jsonに、BettingTotal:Int 項目を追加した後に発生した為、
こちらが一因かと思われるのですが、答えにたどり着けません。
検索してみましたが該当する答えが見つからず困っております。
アドバイスいただけると幸いです!
■Firebaseから取得するコード
class EventAll: UIView { var items = [NSDictionary]() --- func loadFirebaseAllData(FirebaseURL:String, completion: @escaping ( ( [NSDictionary]) -> Void ) ) { let firebase = Database.database().reference(fromURL:"(FirebaseURL)") firebase.observe(.value){(snapshot,error) in var tempItems = [NSDictionary]() for item in (snapshot.children){ let child = item as! DataSnapshot let dict = child.value **tempItems.append(dict as! NSDictionary)** } ** self.items = tempItems** completion( self.items ) } }
■取得したコードをTableViewへ *一部省略
class MainThirdViewController:UIViewController,IndicatorInfoProvider,UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate{ let firebaseFunction = EventAll() var items = [NSDictionary]() --- override func viewDidLoad() { super.viewDidLoad() //tableview tableView.delegate = self tableView.dataSource = self tableView.rowHeight = displayHeight / 3 firebaseFunction.loadFirebaseAllData( FirebaseURL:"https://viv-app-ce54b.firebaseio.com/Schedule/Day1"){ items in self.items = items print(items) self.tableView.reloadData()} --- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "ContentsTableViewXib") as! ContentsTableViewXib cell.selectionStyle = UITableViewCellSelectionStyle.none let dict = items[(indexPath as NSIndexPath).row] //ここで代入 let contentsTableTitle = cell.viewWithTag(1) as! UILabel contentsTableTitle.text = dict["Title"] as? String let contentsTableImage = cell.viewWithTag(3) as! UIImageView imageURL = dict["Image"] as? String let url = NSURL(string: "(imageURL!)") contentsTableImage.kf.setImage(with: ImageResource(downloadURL: url as! URL), options: [.cacheMemoryOnly], completionHandler: { (image, error, cacheType, imageUrl) in }) --- return cell }
■エラー表示分
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1c0290360 'UISV-canvas-connection' UIStackView:0x108794370.leading == UILabel:0x108794580'〆:2018/10/21 12:00'.leading (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
Could not cast value of type '__NSCFString' (0x1b4ead5e8) to 'NSDictionary' (0x1b4eae768).
**2018-11-06 23:00:36.910415+0900 FANCAS[12165:3644397] Could not cast value of type '__NSCFString' (0x1b4ead5e8) to 'NSDictionary' (0x1b4eae768).
(lldb) **
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。