Справка по CountMeIn: добавьте 1 к UILabel2, если значение UILabel1 равно UITextField - PullRequest
0 голосов
/ 03 сентября 2011

Я абсолютный новичок, а не говорю по-английски ... Я пытаюсь воспроизвести и изменить код CountMeIn, который вы можете найти на http://appsamuck.com/day5.html. Я реализовал больше счетчиков, (Score1, Score2,set1, set2) и поле для "race to:", что я хотел бы:

"race to" может быть установлено любое значение;Я хотел бы, чтобы, когда оценка1 была равна или больше (+ =), чем «гонка на», это сбрасывало оценки 1 и 2, и добавляло 1 к set1.Тогда то же самое для Score2 ... вот мой код:

MainView.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface MainView : UIView {
    IBOutlet UILabel *scorer;
    IBOutlet UILabel *seter;
    IBOutlet UILabel *scorer1;
    IBOutlet UILabel *seter1;
    IBOutlet UITextField *racer; // "race  to"
}

- (IBAction)doneButtonOnKeyboardPressed: (id)sender;
- (IBAction)addUnit;
- (IBAction)subtractUnit;
- (IBAction)addUnit2;
- (IBAction)subtractUnit2;
- (IBAction)addUnit3;
- (IBAction)subtractUnit3;
- (IBAction)addUnit4;
- (IBAction)subtractUnit4;
- (IBAction??)countset; // ->?
- (IBAction??)countset1; // ->?
@end

MainView.m

#import "MainView.h"

    @implementation MainView

    int score = 00;
    int set = 00;
    int score1 = 00;
    int set1 = 00;
    int race = 00;

    -(void)awakeFromNib; {

        scorer.text = @"00";
        seter.text = @"00";
        scorer1.text = @"00";
        seter1.text = @"00";
        racer.text = @"00";

    }

    - (IBAction)addUnit {

        if(score >= 99) return;

        NSString *numValue = [[NSString alloc] initWithFormat:@"%02d", ++score];
        scorer.text = numValue;
        [numValue release];


        if(scorer.text == racer.text) return;

        NSString *numValue1 = [[NSString alloc] initWithFormat:@"%02d", ++set];
        seter.text = numValue1;
        [numValue1 release];
    }

    - (IBAction)subtractUnit {

        if(score <= 00) return;

        NSString *numValue = [[NSString alloc] initWithFormat:@"%02d", --score];
        scorer.text = numValue;
        [numValue release]; 
    }

    - (IBAction)addUnit2 {

        if(set >= 99) return;

        NSString *numValue = [[NSString alloc] initWithFormat:@"%02d", ++set];
        seter.text = numValue;
        [numValue release];
    }

    - (IBAction)subtractUnit2 {

        if(set <= 00) return;

        NSString *numValue = [[NSString alloc] initWithFormat:@"%02d", --set];
        seter.text = numValue;
        [numValue release]; 
    }

    - (IBAction)addUnit3 {

        if(score1 >= 99) return;

        NSString *numValue = [[NSString alloc] initWithFormat:@"%02d", ++score1];
        scorer1.text = numValue;
        [numValue release];

    }

    - (IBAction)subtractUnit3 {

        if(score1 <= 00) return;

        NSString *numValue = [[NSString alloc] initWithFormat:@"%02d", --score1];
        scorer1.text = numValue;
        [numValue release]; 
    }

    - (IBAction)addUnit4 {

        if(set1 >= 99) return;

        NSString *numValue = [[NSString alloc] initWithFormat:@"%02d", ++set1];
        seter1.text = numValue;
        [numValue release];

    }

    - (IBAction)subtractUnit4 {

        if(set1 <= 00) return;

        NSString *numValue = [[NSString alloc] initWithFormat:@"%02d", --set1];
        seter1.text = numValue;
        [numValue release]; 
    }


    - (IBAction)countset{ // I guess its no IBAction...

        if(scorer.text += racer.text add 1 to setter.text  // ->? i can't figure out...

Может кто-нибудь помочь мне, пожалуйста?Есть наверняка еще один способ написать это с меньшим количеством кода, но я узнаю позже, я рад, что это работает до сих пор.Спасибо за любую помощь, и извините за мой английский.

Ответы [ 2 ]

0 голосов
/ 05 сентября 2011

, поэтому я выполнил тестирование и настройку, но он еще не полностью работает;

'countset' не должен быть действием, так как он должен проверять каждый раз при изменении оценки, поэтому лучший способ - это добавитьэто к действию 'addUnit':

    - (IBAction)addUnit {


    if(score >= 99) return;

    NSString *numValue = [[NSString alloc] initWithFormat:@"%02d", ++score];
    scorer.text = numValue;
    [numValue release];

// compare values
if ([scorer.text intValue] >= [racer1.text intValue])
{
    // add 1
    seter.text = [NSString stringWithFormat:@"%02d", [seter.text intValue] + 1];
    // reset values
    scorer.text = @"00";
}

это работает, для первого сета, но потом я предполагаю, что чего-то не хватает, релиз, вероятно, теперь это работает, но после того, как первый набор забит, счет сбрасывается, но он добавляет один набор на каждую новую точку ... Кроме того, если произошла ошибка, я не могу вычесть единицу в набор, сначала я должен добавить один, прежде чем я могу вычесть ...

надеюсь, вы понимаете, и извините, если я не отвечу на свой вопрос.

0 голосов
/ 03 сентября 2011

Если я правильно понимаю ваш вопрос, то вот решение:

- (IBAction)countset
{
    // compare values
    if ([scorer.text intValue] >= [racer.text intValue])
    {
        // add 1
        setter.text = [NSString stringWithFormat:@"%02d", [setter.text intValue] + 1];
        // reset values
        score1.text = @"";
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...