Cocoa touch tableview:cellforrowatindexpath具有多个单元格类型

Cocoa touch tableview:cellforrowatindexpath具有多个单元格类型,cocoa-touch,uitableview,Cocoa Touch,Uitableview,当我构建和分析时,我被告知cell永远不会得到一个值……根据我的逻辑,这个值似乎是错误的,但是当应用程序试图加载表时崩溃了。那么…为什么来 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *Cell1Identifier = @"Cell1";

当我构建和分析时,我被告知cell永远不会得到一个值……根据我的逻辑,这个值似乎是错误的,但是当应用程序试图加载表时崩溃了。那么…为什么来

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

        static NSString *Cell1Identifier = @"Cell1";
        static NSString *Cell2Identifier = @"Cell2";
        static NSString *Cell3Identifier = @"Cell3";
        UITableViewCell *cell;

        if ([indexPath section] == 0) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell1Identifier];

            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
                                               reuseIdentifier:Cell1Identifier] autorelease];
            }
        }

        else if ([indexPath section] == 1) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell3Identifier];
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                               reuseIdentifier:Cell3Identifier] autorelease];
            }
        }

        else {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell2Identifier];
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                               reuseIdentifier:Cell2Identifier] autorelease];
            }
        }


        // Configure the cell...
        [self configureCell:cell
                atIndexPath:indexPath];

        return cell;
    }
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *Cell1Identifier = @"Cell1";
    static NSString *Cell2Identifier = @"Cell2";
    static NSString *Cell3Identifier = @"Cell3";
    NSString *identityString = @"";
    switch ([indexPath section]) {
        case 0: {
            identityString = Cell1Identifier;
            break;
        }
        case 1: {
            identityString = Cell3Identifier;
            break;
        }
        case 2: {
            identityString = Cell2Identifier;
            break;
        }

        default:
            break;
    }

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identityString];

    if ([indexPath section] == 0) {

        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
                                           reuseIdentifier:Cell1Identifier] autorelease];
        }
    }

    else if ([indexPath section] == 1) {
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                           reuseIdentifier:Cell3Identifier] autorelease];
        }
    }

    else {
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                           reuseIdentifier:Cell2Identifier] autorelease];
        }
    }


    // Configure the cell...
    [self configureCell:cell
            atIndexPath:indexPath];

    return cell;
}