Ios 为什么表视图不显示任何内容?
我有一个正确设置的表视图,但没有显示任何内容。阵列已填充,所有代理都已正确设置。我该如何解决这个问题?Ios 为什么表视图不显示任何内容?,ios,swift,Ios,Swift,我有一个正确设置的表视图,但没有显示任何内容。阵列已填充,所有代理都已正确设置。我该如何解决这个问题? titleofsong中有数据吗?是的,titleofsong和artist在try tableView中有数据。检索内容后重新加载数据(),而不仅仅是发布代码。请解释错误以及您的答案是如何解决问题的。在func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath)中,您需要使用可重用的单元格。您需要从故事板或在代
titleofsong
中有数据吗?是的,titleofsong和artist在try tableView中有数据。检索内容后重新加载数据(),而不仅仅是发布代码。请解释错误以及您的答案是如何解决问题的。在func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath)中,您需要使用可重用的单元格。您需要从故事板或在代码中注册一个可重用单元。我在上面发布的内容是如何从xib创建自定义单元格。如果您不想使用xib,并且确实想在代码中注册一个可重用的单元格,请签出此帖子:用详细信息更新您的答案,而不是发表评论。
override func viewDidLoad() {
super.viewDidLoad()
self.friendstable.rowHeight = 150.0
friendstable.allowsSelection = false
self.friendstable.dataSource = self
self.friendstable.delegate = self
self.friendstable.registerClass(UITableViewCell.self, forCellReuseIdentifier: "friendcell")
// Do any additional setup after loading the view.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titleofsong.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//var cell = friendstable.dequeueReusableCellWithIdentifier("friendcell", forIndexPath: indexPath)
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "friendcell")
cell.textLabel?.text = titleofsong[indexPath.row]
cell.detailTextLabel?.text = artist[indexPath.row]
cell.textLabel?.font = UIFont(name: "Lombok", size: 22)
cell.textLabel?.textColor = UIColorFromRGB("4A90E2")
cell.detailTextLabel?.font = UIFont(name: "Lombok", size: 16)
cell.detailTextLabel?.textColor = UIColor.blackColor()
cell.textLabel?.numberOfLines = 0;
cell.textLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping
cell.backgroundColor = UIColor.clearColor()
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
self.friendstable.rowHeight = 150.0
friendstable.allowsSelection = false
self.friendstable.dataSource = self
self.friendstable.delegate = self
self.friendstable.registerNib(UINib(nibName:"YOUR_NIB_FILE_NAME", bundle:nil), forCellReuseIdentifier:"friendcell")
// Do any additional setup after loading the view.
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell : UITableViewCell= tableView.dequeueReusableCellWithIdentifier("friendcell", forIndexPath: indexPath)
cell.textLabel?.text = titleofsong[indexPath.row]
cell.detailTextLabel?.text = artist[indexPath.row]
cell.textLabel?.font = UIFont(name: "Lombok", size: 22)
cell.textLabel?.textColor = UIColorFromRGB("4A90E2")
cell.detailTextLabel?.font = UIFont(name: "Lombok", size: 16)
cell.detailTextLabel?.textColor = UIColor.blackColor()
cell.textLabel?.numberOfLines = 0;
cell.textLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping
cell.backgroundColor = UIColor.clearColor()
return cell
}