Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Deltaassissino

macrumors newbie
Original poster
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
 
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
 
modulo always shows pic 1 = that means moulo = 0 but thats wrong ...

Code:
    NSString *theTextField = @"%d";
    int daysPassed = [theTextField floatValue];
    
    
    int imageNumber = daysPassed % 4;

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
 
i want xcode to count the days between 1.1.2012. and he picked dart(that works)
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.