开发者

"Warning reaching end of non-void function" with Multiple Sections that pull in multiple CustomCells within cellForRowAtIndexPath

I'm getting "Reaching end of non-void function" warning, but don't have anything else to return for the compiler. How do I get around the warning??

I'm using customCells to display a table with 3 Sections. Each CustomCell is different, linked with another viewcontroller's tableview within the App, and is getting its data from its individual model. Everything works great in the Simulator and Devices, but I would like to get rid of the warning that I have. It is the only one I have, and it is pending me from uploading to App Store!!

Within the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {, I have used 3 separate If() statements-(i.e.==0,==1,==2) to control which customCells are displayed within each section throughout the tableview's cells. Each of the customCells were created in IB, pull there data from different models, and are used with other ViewController tableViews.

At the end of the function, I don't have a "cell" or anything else to return, because I already specified which CustomCell to return within each of the If() statements.

Because each of the CustomCells are referenced through the AppDelegate, I can not set up an empty cell at the start of the function and just set the empty cell equal to the desired CustomCell within each of the If() statements, as you can for text, labels, etc...

My question is not a matter of fixing code within the If() statements, unless it is required. My Questions is in "How to remove the warning for reaching end of non-void function-(cellForRowAtIndexPath:) when I have already returned a value for every possible case: if(section == 0); if(section == 1); and if(section == 2).

*Code-Reference: The actual file names were knocked down for simplicity, (section 0 refers to M's, section 1 refers to D's, and section 2 refers to B's).

Here is a sample Layout of the code:

//CELL FOR ROW AT INDEX PATH:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPa开发者_如何学JAVAth:(NSIndexPath *)indexPath {

//Reference to the AppDelegate:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

//Section 0:
if(indexPath.section == 0) {

    static NSString *CustomMCellIdentifier = @"CustomMCellIdentifier";

    MCustomCell *mCell = (MCustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomMCellIdentifier];

    if (mCell == nil) {

        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MCustomCell" owner:tableView options:nil];     


        for (id oneObject in nib)
            if ([oneObject isKindOfClass:[MCustomCell class]]) 
                mCell = (MCustomCell *)oneObject;
    }

    //Grab the Data for this item:
    M *mM = [appDelegate.mms objectAtIndex:indexPath.row];

    //Set the Cell
    [mCell setM:mM];

    mCell.selectionStyle =UITableViewCellSelectionStyleNone;

    mCell.root = tableView;

    return mCell;
}


//Section 1:
if(indexPath.section == 1) {

    static NSString *CustomDCellIdentifier = @"CustomDCellIdentifier";

    DCustomCell *dCell = (DCustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomDaddyCellIdentifier];

    if (dCell == nil) {

        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DCustomCell" owner:tableView options:nil];     



        for (id oneObject in nib)
            if ([oneObject isKindOfClass:[DCustomCell class]]) 
                dCell = (DCustomCell *)oneObject;
    }

    //Grab the Data for this item:
    D *dD = [appDelegate.dds objectAtIndex:indexPath.row];

    //Set the Cell
    [dCell setD:dD];

    //Turns the Cell's SelectionStyle Blue Highlighting off, but still permits the code to run!
    dCell.selectionStyle =UITableViewCellSelectionStyleNone;

    dCell.root = tableView;

    return dCell;
}


//Section 2:
if(indexPath.section == 2) {

    static NSString *CustomBCellIdentifier = @"CustomBCellIdentifier";

    BCustomCell *bCell = (BCustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomBCellIdentifier];

    if (bCell == nil) {

                    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"BCustomCell" owner:tableView options:nil];     



        for (id oneObject in nib)
            if ([oneObject isKindOfClass:[BCustomCell class]]) 
                bCell = (BCustomCell *)oneObject;
    }

    //Grab the Data for this item:
    B *bB = [appDelegate.bbs objectAtIndex:indexPath.row];

    //Set the Cell
    [bCell setB:bB];

    bCell.selectionStyle =UITableViewCellSelectionStyleNone;

    bCell.root = tableView;

    return bCell;
}

//** Getting Warning "Control reaches end of non-void function" 

//Not sure what else to "return ???" all CustomCells were specified within the If() statements above for their corresponding IndexPath.Sections.

 }

Any Suggestions ??


You need a return at the End of the function, regardless of whether you're handling the return inside of a {} block. Try:

return nil;

It'll never get executed, but you'll have a return for the compiler. I'd frankly redesign the statement.


Instead of using three separate if statements, change it to if() - else if() - else

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜