Modulo/if statement Problem

Discussion in 'iOS Programming' started by Deltaassissino, Jan 19, 2012.

  1. Deltaassissino macrumors newbie

    Joined:
    Jan 19, 2012
    #1
    hello i have an Modul/ ifstatment problem i don´t see whats wrong...

    i want xcode to count the days between 1.1.2012. and he picked dart(that works)

    so i want to use the modulo to get 0,1,2 or 3 as result and wanna show for 0= pic 1,1= pic 2 etc. can you please help me to find my fail?

    modulo always shows pic 1 = that means moulo = 0 but thats wrong ...

    Code:
    #import "ViewController.h"
    
    @implementation ViewController
    @synthesize theTextField;
    @synthesize imageNumber;
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Release any cached data, images, etc that aren't in use.
    }
    
    #pragma mark - View lifecycle
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        NSCalendar *calendar = [NSCalendar currentCalendar];
        NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
        
        [dateComponents setMonth:01];
        [dateComponents setYear:2012];
        [dateComponents setDay:01];
        NSDate *dateMin = [calendar dateFromComponents:dateComponents];
        
        [dateComponents setMonth:12];
        [dateComponents setYear:2012];
        [dateComponents setDay:31];
        NSDate *dateMax = [calendar dateFromComponents:dateComponents];
        
        [theDatePicker setMinimumDate:dateMin];
        [theDatePicker setMaximumDate:dateMax];
        [theDatePicker setDate: [NSDate date]];
    }
    - (IBAction)myDatepickerChangedAction:(id)sender {
        NSTimeInterval secondsBetween = [[theDatePicker date]  timeIntervalSinceDate:[theDatePicker minimumDate]];
        int diff = secondsBetween / 86400;
        [theTextField setText: [NSString stringWithFormat:@"%d", diff]];
        
        NSString *theTextField = @"%d";
        int daysPassed = [theTextField floatValue];
        
        
        int imageNumber = daysPassed % 4;
        
        
        if (daysPassed%4 == 0){
            Trommel1.hidden =NO;
        Trommel2.hidden =YES;
        Trommel3.hidden =YES; 
            Trommel4.hidden =YES;
        }
        
        if (daysPassed%4 == 1){
            Trommel1.hidden =YES;
        Trommel2.hidden =NO;
        Trommel3.hidden =YES; 
            Trommel4.hidden =YES;
        }
        
        if (daysPassed%4 == 2){
            Trommel1.hidden =YES;
        Trommel2.hidden =YES;
        Trommel3.hidden =NO; 
            Trommel4.hidden =YES;
        }
        
        if (daysPassed%4 == 3){
            Trommel1.hidden =YES;
        Trommel2.hidden =YES;
        Trommel3.hidden =YES; 
            Trommel4.hidden =NO;
        }
    
        
        
    }
    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
        
        
        
    }
    
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    }
    
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    }
    
    - (void)viewWillDisappear:(BOOL)animated
    {
    	[super viewWillDisappear:animated];
    }
    
    - (void)viewDidDisappear:(BOOL)animated
    {
    	[super viewDidDisappear:animated];
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
        } else {
            return YES;
        }
    }
    
    @end
    
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    You seem to have the debug hooks in there to see what is going on.

    What are the values of: TheTextField, daysPassed, imageNumber

    Are they getting set to what you expect?

    B
     
  3. KnightWRX macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #3
    Look at these 3 consecutive lines. Why do you think the result is always the same ?

    What do you think this line does :

    Code:
    NSString *theTextField = @"%d";
    A little food for thought
     
  4. balamw, Jan 19, 2012
    Last edited: Jan 19, 2012

    balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #4
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Accuracy is important in programming, and also when seeking programming help. You should review the "he picked dart" piece and edit it so that it is comprehensible.
     

Share This Page