2011-08-05 4 views
0

je voulais analyser mon projet, et un analyseur de Xcode trouver un certain code mort dans mon rootcontroller Xcode me dire que:code mort avec Xcode anaylser

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

Quelqu'un peut-il me l'expliquer ans comment nettoyer ce code, merci ....

voici mon 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 
+5

Pourriez-vous poster uniquement le code que vous voulez corriger? Il est vraiment difficile de passer par des lignes non pertinentes pour trouver exactement ce dont vous avez besoin ... – Vladimir

+0

* Quelle * ligne ???? – progrmr

+0

@Vladimir [self addSectionAtIndex: 0 avecAnimation: UITableViewRowAnimationFade]; pour (NSInteger i = 0; i <1; i ++) { [self appendRowToSection: 0 cellClass: [classe NibLoadedCell2] CellData: [NSString stringWithFormat: NSLocalizedString (@ "Ceci est rangée% ld", @ ""), i + 1] avecAnimation: (i% 2) == 0? UITableViewRowAnimationLeft: UITableViewRowAnimationRight]; } – a3116b

Répondre

6

Dans votre méthode createRows, vous avez une boucle qui n'exécutera une fois:

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

Par conséquent, des choses comme i + 1 et i % 2 pourrait juste être constantes depuis i sera toujours 0.

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

Votre boucle for commence à 0, se termine à 0. i ++ ne sera jamais exécutée.

1

Vous avez plusieurs boucles de la forme:

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

Ce code est presque vide de sens, mais ... le code dans le corps de la boucle n'exécutera jamais une fois, alors que je == 0 , donc vous pourriez tout aussi bien le sortir de la boucle.

+0

J'ai essayé de changer une certaine valeur, si je change i = 0 en une valeur orner alors la vue de table Sera le nom ou la section et la cellule 0 visibles dedans. si je change i <1 à une valeur de 0 0 N'affichera rien et orvet que 1 affichera la même cellule dans ma section, donc j'ai beaucoup de mêmes cellules – a3116b