第一个IOS程序

来源:互联网 发布:cnc编程兼职工资怎么算 编辑:程序博客网 时间:2024/05/23 22:00

使用ios 程序实现 a+b  

结果用UIAlertView 输出


1  新建一个 SIngleView  IOS project  

2  在 .xib 中拖入控件

3  按住ctrl键进行 refference   

其中文本框使用 outlet  button使用action

4 填充button对应的函数 

代码如下:


- (IBAction)calc:(id)sender {    int a=Text1.text.intValue;    int b=Text2.text.intValue;        int c=a+b;        NSString *str=[[NSString alloc] initWithFormat:@"ans is %d",c];        UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"ANS" message: str delegate:nil  cancelButtonTitle: @"ok~~" otherButtonTitles:nil, nil];    [alert show];        }

当然  使用点语法还要 @synthesize  Text1,Text2;


0 0
原创粉丝点击