罗小罗dykn_uoissui吧 关注:92贴子:2,133
  • 2回复贴,共1
else if(sender == btn){
NSString *str = @"";
intResult = 0;
flag = @"";
[tfShow setStringValue:str];
tfResult = str;
}else if(sender == btnAdd){
NSUInteger location = [tfShow stringValue].length;
NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"+"];
[tfShow setStringValue:str];
if(![flag isEqual: @"+"]){
if([flag isEqual: @"-"]){
intResult = intResult-[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else if([flag isEqual: @"*"]){
intResult = intResult*[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else if([flag isEqual: @"/"]){
intResult = intResult/[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else{
if([tfResult isEqual: @""]){
NSUInteger location = [tfShow stringValue].length;
tfResult = [[tfShow stringValue]substringToIndex:location-1];
}
intResult = [tfResult intValue];
}
flag = @"+";
}else if([flag isEqual: @"+"]){
intResult = intResult+[[tfShow stringValue]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}
}else if(sender == btnSub){
NSUInteger location = [tfShow stringValue].length;
NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"-"];
[tfShow setStringValue:str];
if(![flag isEqual: @"-"]){
if([flag isEqual: @"+"]){
intResult = intResult+[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else if([flag isEqual: @"*"]){
intResult = intResult*[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else if([flag isEqual: @"/"]){
intResult = intResult/[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else{
if([tfResult isEqual:@""]){
NSUInteger location = [tfShow stringValue].length;
tfResult = [[tfShow stringValue]substringToIndex:location-1];
}
intResult = [tfResult intValue];
}
flag = @"-";
}else if([flag isEqual: @"-"]){
intResult = intResult-[[tfShow stringValue]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}
}else if(sender == btnMul){
NSUInteger location = [tfShow stringValue].length;
NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"*"];
[tfShow setStringValue:str];
if(![flag isEqual: @"*"]){
if([flag isEqual: @"+"]){
intResult = intResult+[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else if([flag isEqual: @"-"]){
intResult = intResult-[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else if([flag isEqual: @"/"]){
intResult = intResult/[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else{
if([tfResult isEqual:@""]){
NSUInteger location = [tfShow stringValue].length;
tfResult = [[tfShow stringValue]substringToIndex:location-1];
}
intResult = [tfResult intValue];
}
flag = @"*";
}else if([flag isEqual: @"*"]){
intResult = intResult*[[tfShow stringValue]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}
}else if(sender == btnDiv){
NSUInteger location = [tfShow stringValue].length;
NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"/"];
[tfShow setStringValue:str];
if(![flag isEqual: @"/"]){
if([flag isEqual: @"+"]){
intResult = intResult+[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else if([flag isEqual: @"-"]){
intResult = intResult-[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else if([flag isEqual: @"*"]){
intResult = intResult*[[[tfShow stringValue]substringFromIndex:location+1]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}else{
if([tfResult isEqual:@""]){
NSUInteger location = [tfShow stringValue].length;
tfResult = [[tfShow stringValue]substringToIndex:location-1];
}
intResult = [tfResult intValue];
}
flag = @"/";
}else if([flag isEqual: @"/"]){
intResult = intResult/[[tfShow stringValue]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
}
}else if(sender == btnResult){
if([flag isEqual: @"+"]){
flag = @"y";
intResult = intResult+[[tfShow stringValue]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
[tfShow setStringValue:tfResult];
}else if([flag isEqual: @"-"]){
flag = @"y";
intResult = intResult-[[tfShow stringValue]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
[tfShow setStringValue:tfResult];
}else if([flag isEqual: @"*"]){
flag = @"y";
intResult = intResult*[[tfShow stringValue]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
[tfShow setStringValue:tfResult];
}else if([flag isEqual: @"/"]){
flag = @"y";
intResult = intResult/[[tfShow stringValue]intValue];
NSString *stringInt = [NSString stringWithFormat:@"%d",intResult];
tfResult = stringInt;
[tfShow setStringValue:tfResult];
}
}
}
@end


1楼2017-05-18 18:21回复
    //
    // CountController.m
    // CountApp
    //
    // Created by mac on 5/16/17.
    // Copyright (c) 2017 mac. All rights reserved.
    //
    #import "CountController.h"
    @implementation CountController
    @synthesize window = _window;
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
    // Insert code here to initialize your application
    }
    -(IBAction)btnPress:(id)sender{
    if(sender == btn1){
    if([flag isEqual: @"y"]){
    intResult = 0;
    tfResult = @"";
    [tfShow setStringValue:@""];
    }
    NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"1"];
    [tfShow setStringValue:str];
    }else if(sender == btn2){
    if([flag isEqual: @"y"]){
    intResult = 0;
    tfResult = @"";
    [tfShow setStringValue:@""];
    }
    NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"2"];
    [tfShow setStringValue:str];
    }else if(sender == btn3){
    if([flag isEqual: @"y"]){
    intResult = 0;
    tfResult = @"";
    [tfShow setStringValue:@""];
    }
    NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"3"];
    [tfShow setStringValue:str];
    }else if(sender == btn4){
    if([flag isEqual: @"y"]){
    intResult = 0;
    tfResult = @"";
    [tfShow setStringValue:@""];
    }
    NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"4"];
    [tfShow setStringValue:str];
    }else if(sender == btn5){
    if([flag isEqual: @"y"]){
    intResult = 0;
    tfResult = @"";
    [tfShow setStringValue:@""];
    }
    NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"5"];
    [tfShow setStringValue:str];
    }else if(sender == btn6){
    if([flag isEqual: @"y"]){
    intResult = 0;
    tfResult = @"";
    [tfShow setStringValue:@""];
    }
    NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"6"];
    [tfShow setStringValue:str];
    }else if(sender == btn7){
    if([flag isEqual: @"y"]){
    intResult = 0;
    tfResult = @"";
    [tfShow setStringValue:@""];
    }
    NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"7"];
    [tfShow setStringValue:str];
    }else if(sender == btn8){
    if([flag isEqual: @"y"]){
    intResult = 0;
    tfResult = @"";
    [tfShow setStringValue:@""];
    }
    NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"8"];
    [tfShow setStringValue:str];
    }else if(sender == btn9){
    if([flag isEqual: @"y"]){
    intResult = 0;
    tfResult = @"";
    [tfShow setStringValue:@""];
    }
    NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"9"];
    [tfShow setStringValue:str];
    }else if(sender == btn0){
    if([flag isEqual: @"y"]){
    intResult = 0;
    tfResult = @"";
    [tfShow setStringValue:@""];
    }
    NSString *str = [NSString stringWithFormat:@"%@%@",[tfShow stringValue],@"0"];
    [tfShow setStringValue:str];
    }


    2楼2017-05-18 18:22
    回复
      //
      // CountController.h
      // CountApp
      //
      // Created by mac on 5/16/17.
      // Copyright (c) 2017 mac. All rights reserved.
      //
      #import <Foundation/Foundation.h>
      @interface CountController : NSObject <NSApplicationDelegate>
      {
      IBOutlet NSButton *btn1;
      IBOutlet NSButton *btn2;
      IBOutlet NSButton *btn3;
      IBOutlet NSButton *btn4;
      IBOutlet NSButton *btn5;
      IBOutlet NSButton *btn6;
      IBOutlet NSButton *btn7;
      IBOutlet NSButton *btn8;
      IBOutlet NSButton *btn9;
      IBOutlet NSButton *btn0;
      IBOutlet NSButton *btn;
      IBOutlet NSButton *btnLeft;
      IBOutlet NSButton *btnRight;
      IBOutlet NSButton *btnT;
      IBOutlet NSButton *btnS;
      IBOutlet NSButton *btnAdd;
      IBOutlet NSButton *btnSub;
      IBOutlet NSButton *btnMul;
      IBOutlet NSButton *btnDiv;
      IBOutlet NSButton *btnResult;
      IBOutlet NSTextField *tfShow ;
      int intResult;
      NSString *flag;
      NSString *tfResult;
      }
      @property (assign) IBOutlet NSWindow *window;
      -(IBAction)btnPress:(id)sender;
      @end


      3楼2017-05-18 18:23
      回复