UITableView return 空单元格 swift
UITableView return empty cell swift
在我的 CellForrowAtIndex
我是这样做的
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("HomeCell") as! HomeNewsCellTableViewCell!
if cell == nil
{
tableView.registerNib(UINib(nibName: "HomeNewsCellTableViewCell", bundle: nil), forCellReuseIdentifier: "HomeCell")
// tblNews.registerClass(HomeNewsCellTableViewCell.classForCoder(), forCellReuseIdentifier: "HomeCell")
cell = HomeNewsCellTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "HomeCell")
}
cell.backgroundColor=UIColor.clearColor()
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.imgVwThumb?.image = UIImage(named: "SplashLogo")
cell.imgVwThumb?.contentMode = .ScaleAspectFill
其余代码为单元格标签赋值。
但是在第 7 个单元格中,我得到一个空单元格。
`
cell1
cell2
cell3
empty
cell4
像这样。这是什么原因?我该如何解决这个问题?
请帮我。
谢谢
在 viewDidLoad() 而不是 CellForRow() 中注册单元格笔尖。我正在更改代码,这对你有用。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
(yourTableViewReference).registerNib(UINib(nibName:"HomeNewsCellTableViewCell", bundle: nil), forCellReuseIdentifier: "HomeCell")
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("HomeCell") as! HomeNewsCellTableViewCell
cell.backgroundColor=UIColor.clearColor()
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.imgVwThumb?.image = UIImage(named: "SplashLogo")
cell.imgVwThumb?.contentMode = .ScaleAspectFill
return cell
}
在我的 CellForrowAtIndex
我是这样做的
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("HomeCell") as! HomeNewsCellTableViewCell!
if cell == nil
{
tableView.registerNib(UINib(nibName: "HomeNewsCellTableViewCell", bundle: nil), forCellReuseIdentifier: "HomeCell")
// tblNews.registerClass(HomeNewsCellTableViewCell.classForCoder(), forCellReuseIdentifier: "HomeCell")
cell = HomeNewsCellTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "HomeCell")
}
cell.backgroundColor=UIColor.clearColor()
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.imgVwThumb?.image = UIImage(named: "SplashLogo")
cell.imgVwThumb?.contentMode = .ScaleAspectFill
其余代码为单元格标签赋值。 但是在第 7 个单元格中,我得到一个空单元格。 `
cell1
cell2
cell3
empty
cell4
像这样。这是什么原因?我该如何解决这个问题? 请帮我。 谢谢
在 viewDidLoad() 而不是 CellForRow() 中注册单元格笔尖。我正在更改代码,这对你有用。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
(yourTableViewReference).registerNib(UINib(nibName:"HomeNewsCellTableViewCell", bundle: nil), forCellReuseIdentifier: "HomeCell")
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("HomeCell") as! HomeNewsCellTableViewCell
cell.backgroundColor=UIColor.clearColor()
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.imgVwThumb?.image = UIImage(named: "SplashLogo")
cell.imgVwThumb?.contentMode = .ScaleAspectFill
return cell
}