ios5--計算機

來源:互聯網
上載者:User

標籤:計算機   .text   inter   atomic   一個   interface   結果   相加   hold   

////  ViewController.m//  01-加法計算機////  首先找main.m檔案,然後找AppDelegate,然後找Main Inteferce主互動故事板,然後載入箭頭指向的控制器,然後載入控制器內部的View。//  連線:按住control拖過去然後配置。//  類擴充:私人的屬性和方法。      #import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UITextField *num1TextField;@property (weak, nonatomic) IBOutlet UITextField *num2TextField;@property (weak, nonatomic) IBOutlet UILabel *resultLabel;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    self.num1TextField.placeholder = @"dddd";}- (IBAction)sum {    // 1. 拿到兩個字串    NSString *sum1String = self.num1TextField.text;    NSString *sum2String = self.num2TextField.text;        // 判斷    if (sum1String.length == 0) {        /*        // 建立對象        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"輸入有誤" message:@"請輸入第一個數" delegate:nil cancelButtonTitle:@"我知道了" otherButtonTitles:nil, nil];                // 顯示        [alertView show];        */        [self showInfo:@"請輸入第一個數"];        return;    }        if (sum2String.length == 0) {        /*        // 建立對象        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"輸入有誤" message:@"請輸入第二個數" delegate:nil cancelButtonTitle:@"我知道了" otherButtonTitles:nil, nil];                // 顯示        [alertView show];        */        [self showInfo:@"請輸入第二個數"];        return;    }    // 2. 把字串轉成數值    NSInteger sum1 = [sum1String integerValue];    NSInteger sum2 = [sum2String integerValue];        // 3. 相加    NSInteger result = sum1 + sum2;        // 4. 顯示結果    self.resultLabel.text = [NSString stringWithFormat:@"%zd", result];}//zd是無符號整型- (void)showInfo: (NSString *)info{    // 建立對象    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"輸入有誤" message:info delegate:nil cancelButtonTitle:@"我知道了" otherButtonTitles:nil, nil];        // 顯示    [alertView show];}@end

 

ios5--計算機

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.