0

私は自分のプロジェクトを分析したかったのですが、xcode アナライザーが rootcontroller Xcode でデッド コードを見つけて、次のように教えてくれました:

Dead code
The left operand to '+' is always 0
-> Variable 'i' initialized to 0
-> The left operand to '+' is always 0

誰かが私にこれとそのコードをきれいにする方法を説明できますか、ありがとう....

ここに私の rootcontroller.m があります

#import "RootViewController22.h"
#import "LabelCell.h"
#import "NibLoadedCell.h"
#import "GradientBackgroundTable.h"
#import "NibLoadedCell2.h"
#import "NibLoadedCell3.h"

@implementation RootViewController22

//
// title
//
// returns the navigation bar text for the front screen
//


/*- (NSString *)title
{
    return NSLocalizedString(@"Les Robes du Bengal", @"");
}*/



//
// createRows
//
// Constructs all the rows on the front screen and animates them in
//
- (void)createRows
{


    [self addSectionAtIndex:0 withAnimation:UITableViewRowAnimationFade];
    for (NSInteger i = 0; i < 1; i++)
    {
        [self
         appendRowToSection:0
         cellClass:[NibLoadedCell2 class]
         cellData:[NSString stringWithFormat:
                   NSLocalizedString(@"This is row %ld", @""), i + 1]
         withAnimation:(i % 2) == 0 ?
         UITableViewRowAnimationLeft :
         UITableViewRowAnimationRight];
    }




    //[self addSectionAtIndex:0 withAnimation:UITableViewRowAnimationFade];
    //for (NSInteger i = 0; i < 4; i++)
    //{
    //  [self
    //      appendRowToSection:0
    //      cellClass:[LabelCell class]
    //      cellData:[NSString stringWithFormat:
    //          NSLocalizedString(@"This is row %ld", @""), i + 1]
    //      withAnimation:(i % 2) == 0 ?
    //          UITableViewRowAnimationLeft :
    //          UITableViewRowAnimationRight];
//  }

    [self addSectionAtIndex:1 withAnimation:UITableViewRowAnimationFade];
    for (NSInteger i = 0; i < 1; i++)
    {
        [self
            appendRowToSection:1
            cellClass:[NibLoadedCell3 class]
            cellData:[NSString stringWithFormat:
                NSLocalizedString(@"This is row %ld", @""), i + 1]
            withAnimation:(i % 2) == 0 ?
                UITableViewRowAnimationLeft :
                UITableViewRowAnimationRight];
    }

//  [self addSectionAtIndex:2 withAnimation:UITableViewRowAnimationFade];
//  for (NSInteger i = 0; i < 4; i++)
//  {
//      [self
//          appendRowToSection:2
    //      cellClass:[TextFieldCell class]
    //      cellData:
    //          [NSMutableDictionary dictionaryWithObjectsAndKeys:
    //              [NSString stringWithFormat:
    //                  NSLocalizedString(@"TextField %ld", @""), i + 1],
    //                  @"label",
    //              @"", @"value",
    //              NSLocalizedString(@"Value goes here", @""),
    //                  @"placeholder",
    //          nil]
        //  withAnimation:(i % 2) == 0 ?
    //          UITableViewRowAnimationLeft :
    //          UITableViewRowAnimationRight];
//  }

    [self addSectionAtIndex:2 withAnimation:UITableViewRowAnimationFade];
    for (NSInteger i = 0; i < 1; i++)
    {
        [self
         appendRowToSection:2
         cellClass:[NibLoadedCell class]
         cellData:[NSString stringWithFormat:
                   NSLocalizedString(@"This is row %ld", @""), i + 1]
         withAnimation:(i % 2) == 0 ?
         UITableViewRowAnimationLeft :
         UITableViewRowAnimationRight];
    }


    [self hideLoadingIndicator];
}

//
// refresh
//
// Removes all existing rows and starts a reload (on a 0.5 second timer)
//
- (void)refresh:(id)sender
{
    [self removeAllSectionsWithAnimation:UITableViewRowAnimationFade];
    [self performSelector:@selector(createRows) withObject:nil afterDelay:0.5];
    [self showLoadingIndicator];
}

//
// viewDidLoad
//
// On load, refreshes the view (to load the rows)
//
- (void)viewDidLoad
{
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
     self.title = @"Les Robes";
    [super viewDidLoad];

    self.useCustomHeaders = YES;
    [self refresh:nil];
}

//
// loadView
//
// Since the view is so simple (just a GradientBackgroundView) we might as
// well contruct it in code.
//
- (void)loadView
{
    GradientBackgroundTable *aTableView =
        [[[GradientBackgroundTable alloc]
            initWithFrame:CGRectZero
            style:UITableViewStyleGrouped]
        autorelease];

    self.view = aTableView;
    self.tableView = aTableView;
}

//
// textFieldDidEndEditing:
//
// Update the rowData for the text field rows to match the edited value of the
// text field.
//

//
// tableView:titleForHeaderInSection:
//
// Header text for the three sections
//
// Parameters:
//    aTableView - the table
//    section - the section for which header text should be returned
//
// returns the header text for the appropriate section
//
- (NSString *)tableView:(UITableView *)aTableView
    titleForHeaderInSection:(NSInteger)section
{
    if (section == 0)
    {
        return NSLocalizedString(@"Les Motifs", nil);
    }
    else if (section == 1)
    {
        return NSLocalizedString(@"Les Couleurs", nil);
    }
    else if (section == 2)
    {
        return NSLocalizedString(@"À Savoir", nil);
    }

    return nil;
}

@end
4

3 に答える 3

6

createRowsメソッドには、一度だけ実行されるループがあります。

for (NSInteger i = 0; i < 1; i++) { ... }

したがって、 と のようなものはi + 1、常に であるため、i % 2単なる定数である可能性があります。i0

于 2011-08-05T13:15:50.557 に答える
1

次の形式のループがいくつかあります。

for (NSInteger i = 0; i < 1; i++) { }

ただし、そのコードはほとんど意味がありません... ループの本体のコードは、i == 0 の間は 1 回しか実行されないため、ループから外した方がよいでしょう。

于 2011-08-05T13:20:00.233 に答える
1
for (NSInteger i = 0; i < 1; i++)

for ループは 0 で始まり、0 で終わります。i++ は決して実行されません。

于 2011-08-05T13:16:48.757 に答える