iOS 减法计算器
一:
在界面上拖入相应的控件

二: 给每个控件设置关联
//监听按钮的点击
- (IBAction)compute:(id)sender;
//第一个文本输入框的值
@property (weak, nonatomic) IBOutlet UITextField *numField1;
@property (weak, nonatomic) IBOutlet UITextField *numField2;
@property (weak, nonatomic) IBOutlet UILabel *totalLabel;
三: 处理按钮点击事件
- (IBAction)compute:(id)sender {
//1 取得两个文本输入框的值
NSString *text1 = self.numField1.text;
NSString *text2 = self.numField2.text;
//2 相减
int deffernece = 0;
int num1 = [text1 intValue];
int num2 = [text2 intValue];
if(num1 > num2 || num1 == num2){
deffernece = num1 - num2;
}else{
//弹框
//创建一个弹框
//initWithTitle 标题
//message 详细信息
//delegate 代理
//cancelButtonTitle 取消按钮的文字
//otherButtonTitles 其他按钮的文字
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"输入的数字不合理" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
//2.2显示
[alert show];
}
//3 把结果显示在右边的文本标签中
_totalLabel.text = [NSString stringWithFormat:@"%d",deffernece];
[self.view endEditing:YES];
}
iOS 减法计算器的更多相关文章
- IOS之计算器实现
本文利用ios实现计算器app,后期将用mvc结构重构 import UIKit class CalculViewController: UIViewController { @IBOutlet we ...
- iOS小型计算器
// // ViewController.m // 计算器 //屏幕的宽和高 #define SCREEN_W self.view.frame.size.width #define SCREEN_ ...
- IOS OC 计算器算法(不考虑优先级)
个人见解:为还在计算器算法方面迷惑的同学一个数据处理解决方案:定义一个可变数组array,一个可变字符串str,使字符通过[array addObject:str];方法添加到可变数组,每当触发运算符 ...
- iOS 收款计算器算法
一个收款计算器算法,从之前高仿有赞Demo里面抽离的一个界面 demo 在这里 https://github.com/L-vinCent/calculView_function 显示计算记录 不能连续 ...
- c 语言简单计算器源码
// main.c // 计算器 // Created by qianfeng on 14-7-15. // Copyright (c) 2014年 ___FGY___. All rights ...
- 使用Olami SDK 语音控制一个支持HomeKit的智能家居的iOS程序
前言 HomeKit是苹果发布的智能家居平台.通过HomeKit组件,用户可以通过iphone.iPad和ipod Touch来控制智能灯泡,风扇.空调等支持HomeKit的智能家居,尤其是可以通过S ...
- C++ //多态案例 -计算器类(普通写法 和 多态写法) //利用多态实现计算器 //多态好处: //1.组织结构清晰 //2.可读性强 //3.对于前期和后期扩展以及维护性高
1 //多态案例 -计算器类(普通写法 和 多态写法) 2 3 #include <iostream> 4 #include <string> 5 using namespac ...
- C++核心编程
C++核心编程 本阶段主要针对C++面向对象编程技术做详细讲解,探讨C++中的核心和精髓. 1 内存分区模型 C++程序在执行时,将内存大方向划分为4个区域 代码区:存放函数体的二进制代码,由操作系统 ...
- C++核心篇
C++核心编程 本阶段主要针对C++面向对象编程技术做详细讲解,探讨C++中的核心和精髓. 1 内存分区模型 C++程序在执行时,将内存大方向划分为4个区域 代码区:存放函数体的二进制代码,由操作系统 ...
随机推荐
- macos下安装oh-my-zsh和zsh-autosuggestion
1:安装oh-my-zsh sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/mast ...
- 使用 numpy.random.choice随机采样
使用 numpy.random.choice随机采样: 说明: numpy.random.choice(a, size=None, replace=True, p=None) 示例: >> ...
- JavaScript Math Object 数字
JavaScript Math Object Math Object The Math object allows you to perform mathematical tasks. Math is ...
- 【LeetCode】3. Longest Substring Without Repeating Characters (2 solutions)
Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...
- 通用MYSQL5.5和5.6源码包安装
系统:REDHAT 6.3安装方式:最小化安装1.MYSQL5.5源码安装环境,依懒的安装包 yum install make gcc gcc-c++ ncurses-devel openssl-de ...
- Tomcat 6 部署工程总结,使用JNDI数据源配置
工程需要用JNDI数据源方式部署到tomcat,参考网上文章后,经过配置测试,摸索出来了. 环境说明: 数据库:Oracle9i Web服务器:tomcat-6.0.33 tomcat启动方式 ...
- Java读写TXT文本
public String readTxtFile(String filePath) { StringBuffer appInfolistInput = new StringBuffer(); try ...
- elk之elasticsearch 入门
一.概述: 1.查看elasticsearch集群的健康状况: [root@node115 kibana]# curl -X GET http://192.168.39.115:9200/_cat/h ...
- IIS的应用程序池优化方法
IIS应用程序池优化方案 服务器经常产生“应用程序池 'DefaultAppPool' 提供服务的进程关闭时间超过了限制.进程 ID 是 '3504'.”的错误,导致iis处于假死状态,经了解是IIS ...
- You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgrou
最近有个同事问我,他工程运行时就会有如下提示,但是不影响功能:You've implemented -[<UIApplicationDelegate> application:didRec ...