Ios segue不使用UITableViewCell alloc,但将ReusableCellWithIdentifier退出队列

Ios segue不使用UITableViewCell alloc,但将ReusableCellWithIdentifier退出队列,ios,uitableview,segue,Ios,Uitableview,Segue,我正在UINavigationController中使用带UITableView的情节提要。 在此UITableView中,使用了具有内部属性的自定义tableViewCell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CustomTableViewCell *cell = nil; if (SYSTEM_VE

我正在UINavigationController中使用带UITableView的情节提要。 在此UITableView中,使用了具有内部属性的自定义tableViewCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    CustomTableViewCell *cell = nil;

    if (SYSTEM_VERSION_LESS_THAN(@"6.0") ) {

        //iOS 6.0 below
        cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    }
    else {
        //iOS 6.0 above

        cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; //work segue

    }
以上代码与push segue配合良好。但当我使用

     cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];   //not work segue
我使用这个alloc方法来保存单元格的数据,避免重用单元格

这只是alloc vs deque。。方法差异。我错过了什么

编辑)我知道不使用dequeReusableCell方法对于性能是有害的。但是,细胞的数量不会很多。这就是为什么我不需要deque方法

  • “不工作”是指“不执行推送序列”,而不是崩溃

    它显示的单元格与使用可取消查询方法时的单元格相同,只是单元格右侧有一个显示指示器图标。指示器图标来自故事板设置

    当我触摸电池时,电池亮显为蓝色,但推送序列不执行

  • CustomTableViewCell有4个属性。这与UITableViewCell完全不同。用户在DetailViewController上设置属性(将segue lead推到该位置)。单元格没有IBOutlet ref。在MasterViewController(具有tableView)中,CellForRowatineXpath方法返回上述代码的CustomTableViewCell

  • cellForRowAtIndexPath方法在CustomTableViewCell的指示器左侧添加一个开/关按钮 并为单元格设置标记号


  • 使用
    dequeueReusableCellWithIdentifier
    可以使用原型单元。如果您使用
    initWithStyle
    而不是
    dequeueReusableCellWithIdentifier
    ,那么您不会这样做,因此您也会丢失您为这些单元原型定义的任何序列、公开指示符和其他UI外观

    如果你决定走这条路,你必须走“老派”(也就是说,做我们在细胞原型之前都做过的事情)并编写你自己的
    didSelectRowForIndexPath
    。但是,如果已经定义了该segue,假设您将其称为“SelectRow”,那么您的
    didSelectRowForIndexPath
    可以执行以下操作:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
        [self performSegueWithIdentifier:@"SelectRow" sender:cell];
    }
    
    如果您需要有披露指示器,则您的自定义单元格例程(或
    cellForRowAtIndexPath
    )必须手动设置该指示器。如果你加上

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    
    然后您需要手动处理它:

    - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
        [self performSegueWithIdentifier:@"SelectAccessory" sender:cell];
    }
    

    总之,你可以让它工作,但你只是做了很多额外的工作,失去了退出队列单元的性能和内存优势。我衷心鼓励您重新考虑不使用
    dequeueCellWithIdentifier

    注意,在使用故事板时,
    dequeueReusableCellWithIdentifier
    将始终为您提供一个单元格。谢谢。清楚明了的回答。谢谢你的建议。