Xcode模拟器表视图是黑色的
在模拟器中运行我的Xcode项目时,我的UIViewController
(不是UITableViewController
)中的UITableViewController
是黑色的。
这是我的模拟器的图像:
我的cellForRowAtIndexPath
方法的代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cellIdentifier = "Cell" let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! MyPinpointsTableViewCell // Configure the cell... cell.titleLabel.text = myPinpoints[indexPath.row].title cell.locationLabel.text = myPinpoints[indexPath.row].location cell.dateLabel.text = myPinpoints[indexPath.row].date cell.pinpointImage.image = UIImage(data: myPinpoints[indexPath.row].image) return cell }
这是我的文件夹:
Main.storyboard
:
我将print(myPinpoints)
添加到numberOfRowsInSection
时收到的错误消息
[(entity:Details; id:0xd000000000080000; data:)] [(entity:Details; id:0xd000000000080000; data:)] [(entity:Details; id:0xd000000000080000; data:)] [(entity:Details; id: 0xd000000000080000; data:)] [(entity:Details; id:0xd000000000080000; data:)] [(entity:Details; id:0xd000000000080000; data:)] [(entity:Details; id:0xd000000000080000; data:)] [( entity:Details; id:0xd000000000080000; data:)] [(entity:Details; id:0xd000000000080000; data:)] [(entity:Details; id:0xd000000000080000; data:)] [(entity:Details; id:0xd000000000080000;数据:))
你可能会错过一些东西:
1)检查tableView是否在代码中设置了名为on的类。 您可以在tableView的“属性”检查器中找到输入字段以键入类的名称。
2)检查是否实现了符合UITableViewDelegate和UITableViewDataSource协议的方法。
func numberOfSections(in tableView: UITableView) -> Int { // I see you only have 1 section now return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { //you should return appropriate number return 3 }
3)检查您的表是否从Storyboard正确连接到您的UIViewController =>
由于你的tableView在UIViewController中,检查你是否在控制器中为tableView设置了委托和数据源(CTRL从表格拖动到FileOwner – 故事板场景框架中的圆形黄色图标。)
4)确保您设置UIViewController应符合的协议 – 即delegate和dataSource协议:
class MyPinpointsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { ...
5)检查您的数据源 ,因为它可能没有返回cellForRow()
方法中的任何项目。 它可以通过在任何TableView的委托方法中的print(dataSource)
中进行简单测试。
6)检查可能的自动布局问题 ,因为重要的子视图可能超出视图的可见部分。