[英]Nothing appearing in UITableView cell
I am working on an app that needs to display five different images inside of five different tableview cells. 我正在开发一个需要在五个不同的tableview单元中显示五个不同图像的应用程序。 This is the storyboard that I have for the cell.
这是我为该单元提供的情节提要。
This is the code I have inside of the tableviewcontroller. 这是我在tableviewcontroller内部的代码。
class MasterViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource {
var returnTable = 1
var icons: [String] = ["settings", "calendar", "classes", "envelope", "grades"]
override func viewDidLoad() {
super.viewDidLoad()
// 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 Potentially incomplete method implementation.
// Return the number of sections.
return 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return icons.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! HomeScreenCells
var image : UIImage = UIImage(named: icons[indexPath.row])!
cell.icon.image = image
return cell
}
I also have a custom class for the tableviewcells. 我还为tableviewcells提供了一个自定义类。 Also, I have the correct reuse identifier for the cell.
另外,我具有该单元格的正确重用标识符。 Still, the image does not appear.
仍然没有出现图像。 Not only does the image not appear, nothing appears.
不仅不会出现图像,而且什么也不会出现。 When I change the background, the background does not change in the simulator.
当我更改背景时,模拟器中的背景不会更改。 This is all I get in the simulator.
这就是我在模拟器中得到的全部。
I have the classes linked up correctly for the split view controller. 我已经为拆分视图控制器正确链接了这些类。 I have no idea why nothing is appearing in the table.
我不知道为什么桌上什么也没出现。 Any help would be appreciated.
任何帮助,将不胜感激。
我认为您的问题可能是您将节数设置为0。或者将其设置为1,或者完全省略了代码块。
As stated above, return 1 in number of sections (or the number of cells you need). 如上所述,返回1的节数(或所需的单元格数)。 And if your custom cell class has a .xib, you also need to register it, sometimes after you init the tableview
而且,如果您的自定义单元格类具有.xib,则还需要注册它,有时是在初始化tableview之后
tableView.registerNib( UINib(nibName: "HomeScreenCells", bundle: nil), forCellReuseIdentifier: "Cell")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.