2016-06-28 14 views
0

私のデータはオブジェクトメニューを作成することで、メニューという名前のモーダルクラスに入っています。今、どのように私はすべてのデータがテーブルビューにデータを表示するためのコードを追加したobject.Iメニューの助けによって、Menuクラスに保存されている特定のセルクラスモデルからテーブルビューにデータを取り込む方法

var menus = [Menu]() 
        for (_, content) in json { 
         let menu = Menu(id: Int(content["id"].stringValue), 
          name: content["name"].string, 
          image: content["image"].string, 
          coupon: content["coupon"].int, 
          icon: content["icon"].string, 
          order: Int(content["order"].stringValue), 
          aname: content["name"].string, 
          options: Int(content["options"].stringValue), 
          subcategory:content["subcategory"].arrayObject) 

         menus.append(menu) 
        } 
        for menu in menus { 
         print(menu.name) 
         print(menu.id) 
         print(menu.subcategory) 
        } 
        print(menus.count) 

ここに表示するテーブルビューにメニュー名を送信することができます。ここで私はカスタムテーブルビューを作成し、それを設定しようとしています

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 { 

    return menus.count 

} 


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("Menucell", forIndexPath: indexPath)as! MENUTableViewCell 

    cell.Ordermenu.text = (" \(menus[indexPath.row])")///here its not fetching the value 
    return cell 


    } 

それは機能しません。実装はどのようにすべきか?

enter image description here

それはprojectName.classname

enter image description here

答えて

1

以下のコード行を試してみてください。それがあなたを助けてくれることを願って...

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
let cell = tableView.dequeueReusableCellWithIdentifier("Menucell", forIndexPath: indexPath)as! MENUTableViewCell 
let menu : Menu = menus[indexPath.row] 
cell.Ordermenu!.text = menu. name 
return cell 


} 
+0

ええ、このオプションの値(値)は任意です。 –

+0

私の答えごとにコードを変更した後の画面のスクリーンショットを付けることはできますか? –

+0

ええ、あなたのコードは機能していますが、マイナーエラーだけです –

0

答えを受け入れた後に更新を示しますが、表のセルを登録しますか?このようなものを試してみてください...

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    var cell: MENUTableViewCell! = tableView.dequeueReusableCellWithIdentifier("MENUTableViewCellIDENTIFIER") as? MENUTableViewCell 

    if cell == nil 
    { 
     let nib: UINib = UINib(nibName:"MENUTableViewCell", bundle: nil) 

     tableView.registerNib(nib, forCellReuseIdentifier:"MENUTableViewCellIDENTIFIER") 
     cell = tableView.dequeueReusableCellWithIdentifier("MENUTableViewCellIDENTIFIER") as! CompactIncidentCellView 
     //cell.selectionStyle = UITableViewCellSelectionStyle.None 
    } 

    // work with cell here... 
    cell.Ordermenu.text = (" \(menus[indexPath.row])") 

    return cell 
} 
+0

実際に私は単一のメッセージを表示しようとしました。 –

+0

問題はメニュークラスモデル –

+0

ああからカウントを取得していない "menus.count"にあります。私は実際に答えを得た。私はテーブルビューをリロードすることを忘れないでください –

関連する問題