2016-03-10 4 views
-2

Ячейки Tableview пусты. Я пробовал несколько раз, и он всегда создает пустые ячейки для моего табличного представления.Ячейки Tableview всегда пусты

Любая помощь пожалуйста? Спасибо.

import UIKit 

class GroupsTableViewController: UITableViewController /* UITableViewDataSource, UITableViewDelegate */ { 


@IBOutlet weak var table: UITableView! 


var items=["Dog","Cat","Cow","Platypus"] 

override func viewDidLoad() { 
    super.viewDidLoad() 

    self.table.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell") 
    self.table.dataSource = self 
    self.table.delegate = self 

    // Uncomment the following line to preserve selection between presentations 
    // self.clearsSelectionOnViewWillAppear = false 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem() 
} 

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 0 
} 

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 = self.table.dequeueReusableCellWithIdentifier("cell")! as UITableViewCell 
    cell.textLabel!.text = self.items[indexPath.row] 

    // Configure the cell... 

    return cell 
} 

     override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { 
    print("You tapped on cell # \(indexPath.row)") 
} 
+3

'numberOfSectionInTableView' должен быть по крайней мере 1 – Lee

+0

я думал "self.table.dataSource = я" имел в виду, что это было. – O295694

+0

@lee спасибо, я чувствую себя глупо за то, что не обратил внимания. – O295694

ответ

1

попробовать это

override func numberOfSectionsInTableView(tableView: UITableView) ->   Int { 
// #warning Incomplete implementation, return the number of sections 
return 1 
} 
+1

Или полностью удалить эту функцию, так как по умолчанию она равна 1, если не реализована. – rmaddy

0

Вы дали return 0 в numberOfSectionsInTableView методе. numberOfSectionsInTableView должен возвращать стоимость больше, чем 1.

Если у вас есть только один section в UITableView, вы можете удалить этот метод, потому что по умолчанию он будет отображаться только на section в UITableView.

или вы можете попробовать это.

override func numberOfSectionsInTableView(tableView: UITableView) ->   Int { 
    // #warning Incomplete implementation, return the number of sections 
    return 1 
} 
Смежные вопросы