Xcode模拟器表视图为黑色 [英] Xcode simulator table view is black

查看:90
本文介绍了Xcode模拟器表视图为黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在模拟器中运行Xcode项目时,UIViewController(不是UITableViewController)中的UITableView是黑色.

When running my Xcode project in the simulator, my UITableView in my UIViewController (not UITableViewController) is black.

这是我的模拟器的图像:

Here is an image of my simulator:

我的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

[(实体:Details; id:0xd000000000080000; data :) [(实体:详细信息; id:0xd000000000080000;数据:) [(实体:详细信息; id:0xd000000000080000;数据:) [(实体:详细信息; id:0xd000000000080000;数据:) [(实体:详细信息; id:0xd000000000080000;数据:) [(实体:Details; ID:0xd000000000080000;数据:) [(实体:详细信息; id:0xd000000000080000;数据:) [(实体:详细信息; id:0xd000000000080000;数据:) [(实体:详细信息; id:0xd000000000080000;数据:) [(实体:详细信息; id:0xd000000000080000;数据:) [((实体:详细信息; id:0xd000000000080000;数据:))

[ (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 ; data: )]

推荐答案

您可能会错过一些东西:

You may miss some stuff:

1)检查您的tableView是否在代码中设置了名为的类.您可以在tableView的属性"检查器中找到输入字段以键入类的名称.

1) Check whether your tableView has set the class named as that on in your code. You find the input field to type the name of the class in Attributes inspector of the tableView.

2)检查是否实现了符合UITableViewDelegate和UITableViewDataSource协议的方法.

2) Check whether you implemented methods, that comform to UITableViewDelegate and UITableViewDataSource Protocol.

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 =>

3) Check whether your table is properly connected from Storyboard to your UIViewController =>

由于tableView位于UIViewController内,请检查是否在控制器中为tableView设置了委托和数据源(将CTRL从表拖动到FileOwner-情节提要场景框架中的圆形黄色图标.)

As your tableView is inside UIViewController, check whether you set delegate and datasource for tableView in your controller (CTRL drag from table to FileOwner - rounded yellow icon in storyboard scene frame.)

4)确保您设置了协议以确保您的UIViewController应该符合-即委托和数据源协议:

4) Make sure, you set protocols that your UIViewController should conform to - i.e. delegate and dataSource protocols:

class MyPinpointsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { ... 

5)检查您的数据源,因为它可能没有返回cellForRow()方法中的任何项目.可以简单地在print(dataSource)中的任何TableView委托方法中对其进行测试.

5) Check your datasource, as it may not be returning any items in cellForRow() method. It can by simply tested in print(dataSource) in any of TableView's delegate methods.

6)检查可能的自动布局问题,因为重要的子视图可能不在视图的可见部分.

6) Check possible autolayout issues, as the important subviews could be out of visible part of the view.

这篇关于Xcode模拟器表视图为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆