我在我的一个视图控制器中使用UITableView,并使用名为ListCell的自定义类。正在显示表格视图和单元格,但单元格中的内容未显示,因此单元格为空。但如果按下单元格,它就会执行任务。所以内容在那里,但没有显示。我认为这与我如何将类注册到自定义类型ListCell有关。这是我在viewDidLoad中声明它的方式......
self.tblListView.registerClass(ListCell.self, forCellReuseIdentifier: "Cell")
以上行是否有问题。是什么导致细胞内容不显示?
此外,我尝试启用大小类,但这不起作用。此外,所有单元格都是以编程方式创建的。
以下代码行负责显示单元格数据。
cell.displayAlertData(mutArrAlertList.objectAtIndex(indexPath.row) as! [NSObject : AnyObject])
事情是mutArrAlertList在第一个索引处的对象是可选类型Optional(Temperature)。我认为如果它不是可选的,这将是唯一的方法。该对象正在传递我的推送通知,推送通知发送的内容不是可选的。所以某处它会随机变成可选类型。有没有办法摆脱围绕它的可选值?
这是行方法的单元格:
func tableView (tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier: String = "Cell"
var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! ListCell
//if cell == nil
//{
//let nib: NSArray = NSBundle.mainBundle().loadNibNamed("ListCell", owner: self, options: nil)
//cell = (nib.objectAtIndex(0) as? ListCell)!
//}
cell.selectionStyle = UITableViewCellSelectionStyle.None
print("")
print("This is cell: \(mutArrAlertList.objectAtIndex(indexPath.row) as! [NSObject : AnyObject])") //did this to check what the value is and it is an optional
cell.displayAlertData(mutArrAlertList.objectAtIndex(indexPath.row) as! [NSObject : AnyObject])
if indexPath.row == mutArrAlertList.count-1
{
if ApplicationDelegate.intPage > mutArrAlertList.count
{
//do nothing
}
else
{
ApplicationDelegate.intPage = ApplicationDelegate.intPage + 10
self.reloadDataFromdb()
}
}
return cell
}