我正在尝试解决如何设置UITableViewCellStyle在iOS 6中使用新方法的时间UITableView.
以前,在创建时UITableViewCell我会更改UITableViewCellStyle枚举以在调用时创建不同类型的默认单元格,initWithStyle:但是从我可以收集的内容来看,情况不再如此.
UITableView州的Apple文档:
返回值:具有关联重用标识符的UITableViewCell对象.此方法始终返回有效单元格.
讨论:出于性能原因,表视图的数据源通常应该在将单元格分配给其tableView:cellForRowAtIndexPath:方法中的行时重用UITableViewCell对象.表视图维护数据源已标记为可重用的UITableViewCell对象的队列或列表.当要求为表视图提供新单元格时,从数据源对象中调用此方法.如果现有单元格可用,则此方法会使现有单元格出列,或者根据先前注册的类或nib文件创建新单元格.
要点:在调用此方法之前,必须使用registerNib:forCellReuseIdentifier:或registerClass:forCellReuseIdentifier:方法注册类或nib文件.
如果为指定的标识符注册了类并且必须创建新的单元格,则此方法通过调用其initWithStyle:reuseIdentifier:方法来初始化该单元格.对于基于nib的单元格,此方法从提供的nib文件加载单元格对象.如果现有单元可用于重用,则此方法将调用单元的prepareForReuse方法.
这是我cellForRowAtIndexPath实现新方法后的新视图:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell_identifier";
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    return cell;
}
到目前为止我的代码工作正常,但总是返回默认样式.我怎样才能改变这个,所以我可以创建细胞与其他风格,比如UITableViewCellStyleDefault,UITableViewCellStyleValue1,UITableViewCellStyleValue2和UITableViewCellStyleSubtitle?
我不想继承子类UITableViewCell,我只想改变默认类型,就像我在iOS 6之前所做的那样.看起来很奇怪Apple会提供增强的方法,但只需要很少的文档来支持它们的实现.
有没有人掌握这个,或遇到类似的问题?我很难找到任何合理的信息.
我有一个带有几个IBOutlets的自定义单元类.我已将该课程添加到故事板中.我连接了所有的插座.我的cellForRowAtIndexPath函数如下所示:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as SwipeableCell
        cell.mainTextLabel.text = self.venueService.mainCategoriesArray()[indexPath.row]
        return cell
    }
这是我的自定义单元类:
class SwipeableCell: UITableViewCell {
    @IBOutlet var option1: UIButton
    @IBOutlet var option2: UIButton
    @IBOutlet var topLayerView : UIView
    @IBOutlet var mainTextLabel : UILabel
    @IBOutlet var categoryIcon : UIImageView
    init(style: UITableViewCellStyle, reuseIdentifier: String!) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
}
当我运行应用程序时,我的所有单元格都是空的.我已经注销self.venueService.mainCategoriesArray(),它包含所有正确的字符串.我也试过把一个实际的字符串等于标签,这会产生相同的结果.
我错过了什么?任何帮助表示赞赏.