Я абсолютный новичок, а не говорю по-английски ... Я пытаюсь воспроизвести и изменить код 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...
Может кто-нибудь помочь мне, пожалуйста?Есть наверняка еще один способ написать это с меньшим количеством кода, но я узнаю позже, я рад, что это работает до сих пор.Спасибо за любую помощь, и извините за мой английский.