Ios tableView只显示一行内容,有时显示两行内容
我想在Viewcontroller中实现一个简单的tableView,但输出不完整。内容仅在一行中可见,有时在两行中可见 经典的事情:Ios tableView只显示一行内容,有时显示两行内容,ios,swift,uitableview,Ios,Swift,Uitableview,我想在Viewcontroller中实现一个简单的tableView,但输出不完整。内容仅在一行中可见,有时在两行中可见 经典的事情: 该类使用以下命令: class MealOfWeekView: UIViewController, UITableViewDelegate, UITableViewDataSource {...} 我安排代表们 override func viewDidLoad() { super.viewDidLoad() self.tableViewFo
- 该类使用以下命令:
class MealOfWeekView: UIViewController, UITableViewDelegate, UITableViewDataSource {...}
- 我安排代表们
override func viewDidLoad() { super.viewDidLoad() self.tableViewFood.delegate = self self.tableViewFood.dataSource = self self.tableViewFood.reloadData() }
- 我使用正确的标识符:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("foodIdent", forIndexPath: indexPath) as! FoodTableViewCell cell.dayLabel?.text = "\(day[indexPath.row])" return cell }
- 返回1节,返回7行
class FoodTableViewCell: UITableViewCell {
@IBOutlet weak var dayLbl: UILabel!
}
我将以下内容添加到我的viewDidLoad行:
self.tableViewFood.registerClass(FoodTableViewCell.self, forCellReuseIdentifier: "foodIdent")
但它不起作用
如果你需要更多的代码,给一个标志
谢谢大家!
看起来像这样:
您的问题在于自定义类FoodTableViewCell,但我将首先验证以下内容
使用表视图的背景您的问题在于自定义类FoodTableViewCell,但我将首先验证以下内容
使用表视图的背景解决方案 我找到了答案 当您使用选项卡栏控制器时,您必须使用
viewdide出现
或viewdire出现
这句话对我很有用:
override func viewWillAppear(animated: Bool) {
self.tableViewFood.delegate = self
self.tableViewFood.dataSource = self
dispatch_async(dispatch_get_main_queue(), {
self.tableViewFood.reloadData()
})
}
解决方案 我找到了答案 当您使用选项卡栏控制器时,您必须使用
viewdide出现
或viewdire出现
这句话对我很有用:
override func viewWillAppear(animated: Bool) {
self.tableViewFood.delegate = self
self.tableViewFood.dataSource = self
dispatch_async(dispatch_get_main_queue(), {
self.tableViewFood.reloadData()
})
}
用
cell.daylab?.text=“\(day[indexPath.row])”
将print(“day:\(day[indexPath.row])”添加到行下方的day
数组中有多少个对象?您可以使用print(day.count)
将其计算出来添加print(“day:\(day[indexPath.row])
用cell.dayLabel?.text=“\(day[indexPath.row])”
在行的正下方,查看您在那里得到了什么。您的day
数组中有多少个对象?您可以使用打印(day.count)
来计算它