2016-04-18 32 views
0

1つのラベルと項目の追加ボタンで単純なセルを表示しようとしています。私はそれを正しく表示することができません。私は多くの時間を費やしましたが、解決策を見つけることができません。
Xcode 7.3 UITableViewControllerセルが正しく表示されない

enter image description here

これは結果である:

enter image description here

ないadd itemボタンなし正しい行がありません。私はcoredataにちょうど2つの項目があります。

これは私のコードです:

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 items.count 
    } 


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

     let data = items[indexPath.row] as Item 

     cell.textLabel?.text = data.body 

     return cell 
    } 

の問題は何ですか?誰も私がadd itemボタンを表示し、正しい行数を表示し、セルの高さを正しくカスタマイズするのを助けることができますか?ありがとうございました。

+0

プロトタイプのセルスタイルは何ですか? – slxl

+0

こんにちは@slxlカスタムスタイル – Akram

答えて

0

最初に、テーブルビューに正しい行数を返します。

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return cellContent.count 
} 

次に、プロトタイプセルに出力するようにします。

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell") 

    cell.textLabel?.text = cellContent[indexPath.row] 

    return cell 
} 

また、適切に動作するように、次のビューコントローラを呼び出すこともできます。

のViewController:のUIViewController、UITableViewDelegate、UITableViewDataSource

最後に一つは、あなたのプロトタイプのセルは、あなたのコード内の一つとして同じ識別子を持っています。私のコードでは、UITableViewCell(... reuseIdentifier: "Cell")でプロトタイプセルの識別子が "Cell"であることを確認します。 View picture to see where to add the identifier in your storyboard

+0

私はこれを行う前に私は私の質問を投稿しました。返信ありがとうございました – Akram

+0

ごめんなさい、もう一度あなたの質問を読んで、あなたはボタンで項目を追加したいと思っていました。ここで私のリポジトリをダウンロードできるリンクがあります。あなたのコードを動作させるためには、多くの変更が必要です。 https://github.com/andresaguero10/todolistapp –

関連する問題