fehler am Timer

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • fehler am Timer

    Hallo, ich habe leider ein Kleines Problem

    vl. kann mir da jemand helfen

    Danke
    ...........................................................................................................................

    @implementation ViewController
    -(void) TimerRun {
    secondsCount = secondsCount -1;
    int minuts = secondsCount / 60;
    int seconds = secondsCount - (minuts *60);

    NSString *timerOutput = [NSString stringWithFormat:@"%2d:%.2d", minuts, seconds];
    countdownLabel.text = timerOutput;

    if (secondsCount == 0){
    [countdownTimer invalidate];
    countdownTimer = nil;

    }


    }
    -(void) setTimer {
    countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerRun) userInfo:nil repeats:YES];
    secondsCount = 180;

    }

    - (void)viewDidLoad{


    [super viewDidLoad];
    [self setTimer];

    .............................................................................................
    ich bekomme immer das:

    int main(int argc, char *argv[])
    {
    @autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }




    was mache ich da falsch?

    MFG
    Mr.Pink

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Mr.Pink ()

  • Was auffällt:
    1. Code ist case sensitiv. TimerRun und timerRun sind zwei unterschiedliche Dinge.
    2. Die Methode, die vom Timer aufgerufen wird, muss einen Parameter haben. Aus der Dokumentation:
      [quote]aSelector
      The message to send to target when the timer fires. The selector must correspond to a method that returns void and takes a single argument. The timer passes itself as the argument to this method.[/quote]
    Michael
  • Super Danke für die schnelle info
    hat geklappt

    hätte nur noch ne frage
    ich möchte gerne das der Timer Tage und Stunden Minuten, sec. anzeigt

    Quellcode

    1. secondsCount = 172800;
    2. }
    3. -(void) TimerRun {
    4. secondsCount = secondsCount -1;
    5. int minuts = secondsCount / 60;
    6. int seconds = secondsCount - (minuts *60);
    7. int hour = secondsCount / minuts/60;
    8. int day = secondsCount / hour/1;
    9. NSString *timerOutput = [NSString stringWithFormat:@"%02d:%02d:%02d:%02d",day, hour, minuts%60, seconds%60];
    10. countdownLabel.text = timerOutput;
    Alles anzeigen

    wenn ich es so eingebe zeigt er nur blödsinn an...

    bitte um Hilfe

    Danke
  • Mr.Pink schrieb:

    wenn ich es so eingebe zeigt er nur blödsinn an...

    Dann überdenk' noch einmal Deinen Algorithmus: Du musst bei der größten EInheit (= Tage) starten. Ich würde es entweder so machen:

    Quellcode

    1. days = FLOOR(count / secsPerDay);
    2. hours = FLOOR((count - days * secsPerDay) / secsPerHour);
    3. mins = FLOOR((count - days * secsPerDay - hours * secsPerHour) / secsPerMin);
    4. secs = FLOOR(((count - days * secsPerDay - hours * secsPerHour - mins * secsPerMin);

    oder mich mit NSDate und dessen Methoden auseinandersetzen.

    Mattes
    Diese Seite bleibt aus technischen Gründen unbedruckt.
  • hallo

    ich brauch ma bitte ne hilfe
    ich kapier das nicht mit dem NSTimer

    Quellcode

    1. -(void) timerRun {
    2. secondsCount = secondsCount -1;
    3. int minuts = secondsCount / 60;
    4. int seconds = secondsCount - (minuts *60);
    5. int hour = secondsCount / minuts/60;
    6. int day = secondsCount / hour/1;
    7. NSString *timerOutput = [NSString stringWithFormat:@"%2d:%2d:%2d:%.2d", day, hour, minuts%60, seconds%60];
    8. countdownLabel.text = timerOutput;
    9. if(secondsCount == 0)
    10. {
    11. [countdownTimer invalidate];
    12. countdownTimer = nil;
    13. countdownLabel.text = @"00:00:00:00";
    Alles anzeigen


    aber es läuft nicht

    was soll ich machen
    ich überlege und probiere schon tage daran...

    Bitte um Hilfe
  • breakpoint:

    Quellcode

    1. NSString *timerOutput = [NSString stringWithFormat:@"%2d:%2d:%2d:%.2d", day, hour, minuts%60, seconds%60];
    2. countdownLabel.text = timerOutput;




    Quellcode

    1. @autoreleasepool {
    2. return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    3. }
    4. }