【发布时间】:2014-06-05 09:15:41
【问题描述】:
我的TapCell1.swift
这是自定义UITableViewCell View
import UIKit
class TapCell1: UITableViewCell
{
@IBOutlet var labelText : UILabel
init(style: UITableViewCellStyle, reuseIdentifier: String!)
{
println("Ente")
super.init(style: UITableViewCellStyle.Value1, reuseIdentifier: reuseIdentifier)
}
override func setSelected(selected: Bool, animated: Bool)
{
super.setSelected(selected, animated: animated)
}
}
我的 ViewController.swift
它的所有数据源和委托都设置正确。但我的自定义单元格没有显示。
import UIKit
class NextViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
{
@IBOutlet var label: UILabel
@IBOutlet var tableView : UITableView
var getvalue = NSString()
override func viewDidLoad()
{
super.viewDidLoad()
label.text="HELLO GOLD"
println("hello : \(getvalue)")
self.tableView.registerClass(TapCell1.self, forCellReuseIdentifier: "Cell")
}
func tableView(tableView:UITableView!, numberOfRowsInSection section:Int)->Int
{
return 5
}
func numberOfSectionsInTableView(tableView:UITableView!)->Int
{
return 1
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
{
var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TapCell1
cell.labelText.text="Cell Text"
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
问题是我的自定义单元格未显示。请提出我做错的任何事情。
注意:这是我的代码My File Download Link
【问题讨论】:
-
你确定这条线是正确的吗?
self.tableView.registerClass(TapCell1.self, forCellReuseIdentifier: "Cell")尝试删除 .self -
TapCell1.self等价于 Objective-C 中的TapCell1.class。 -
好的,我会检查@eXhausted
-
你用的是板还是笔尖?
标签: ios uitableview swift customization