所以我为我的学校制作了一个RSS阅读器并完成了代码.我跑了测试,它给了我这个错误.这是它所指的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
if (cell == nil) {
cell =
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}
Run Code Online (Sandbox Code Playgroud)
这是输出中的错误:
2012-10-04 20:13:05.356 Reader [4390:c07] *断言失败 - [UITableView dequeueReusableCellWithIdentifier:forIndexPath:],/ SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:4460 2012-10-04 20: 13:05.357 Reader [4390:c07]*由于未捕获异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法使用标识符Cell对单元格进行出列 - 必须为标识符注册一个nib或类,或者在故事板中连接原型单元格" *第一掷调用堆栈:(0x1c91012 0x10cee7e 0x1c90e78 0xb64f35 0xc7d14 0x39ff 0xd0f4b 0xd101f 0xb980b 0xca19b 0x6692d 0x10e26b0 0x228dfc0 0x228233c 0x228deaf 0x1058cd 0x4e1a6 0x4ccbf 0x4cbd9 0x4be34 0x4bc6e 0x4ca29 0x4f922 0xf9fec 0x46bc4 0x47311 0x2cf3 0x137b7 0x13da7 0x14fab …
非常简单的代码:
func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
return 1
}
func tableView(tableView:UITableView!, numberOfRowsInSection section:Int) -> Int {
return 5
}
func tableView(tableView:UITableView!, cellForRowAtIndexPath indexPath:NSIndexPath!) -> UITableViewCell! {
let cell: BookTableViewCell = BookTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "BookCell")
println("ip: \(indexPath.row)")
cell.bookLabel.text = "test"
return cell
}
Run Code Online (Sandbox Code Playgroud)
在cell.bookLabel.text行我得到这个:
fatal error: unexpectedly found nil while unwrapping an Optional value
Run Code Online (Sandbox Code Playgroud)
BookTableViewCell的定义如下:
class BookTableViewCell: UITableViewCell {
@IBOutlet var bookLabel: UILabel
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, …Run Code Online (Sandbox Code Playgroud)