我想要一个UITableView使用的带subtitle式单元格dequeueReusableCellWithIdentifier.
我原来的Objective-C代码是:
static NSString* reuseIdentifier = @"Cell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if(!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
}
Run Code Online (Sandbox Code Playgroud)
在UITableViewSO上搜索了几个问题之后,我想在Swift中写这样的话:
tableView.registerClass(UITableViewCell.classForCoder(), forCellReuseIdentifier: "Cell")
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
Run Code Online (Sandbox Code Playgroud)
但这并没有让我说我想要一种subtitle风格.所以我尝试了这个:
var cell :UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell")
Run Code Online (Sandbox Code Playgroud)
这给了我一个subtitle细胞,但它不让我dequeueReusableCellWithIdentifier.
我已经研究了一些并看了这个视频教程,但他创建了一个单独subclass的UITableViewCell,我认为是不必要的,因为我之前在Obj-C中完成了相同的效果.
有任何想法吗?谢谢.