ios学习笔记(二)xcode 4.3.2下实现基本交互
来源:互联网 发布:阿里云客服抢班语录 编辑:程序博客网 时间:2024/05/15 19:22
想必大家都阅读过iphone4与ipad2开发基础教程吧,这本书的xcode与现在的最新版本有些区别,去掉了view base application,只有比较接近的single view application.
首先我们创建一个single view application,注意这里我们不用自动引用计数。
接着我们点击工程列表中的MainStoryboard_iphone.storyboard 来编辑界面:
我们创建两个按钮和一个用来输出的空白文本:
目录结构与视图结构:
2.接着我们写代码来用来与IB界面编辑器来进行连接:在这里我们可以认为IBOutlet是与IB交互的输出,而IBAction则是IB交互的事件。
先编写ViewContoller.h:
#import <UIKit/UIKit.h>@interface ViewController : UIViewController{}@property (nonatomic,retain) IBOutlet UILabel * statusText;-(IBAction)buttonPressed:(id)sender;@end
接着在ViewContoller.m来实现功能:
#import "ViewController.h"@implementation ViewController@synthesize statusText;-(IBAction)buttonPressed:(id)sender{ NSString *title = [sender titleForState:UIControlStateNormal];//sender用于获得了不同的button的文字 titleForState是根据button状态获取文字的函数 NSString *newText = [[NSString alloc] initWithFormat:@"%@ button pressed.", title];//将title中的文字放入newText中 statusText.text = newText; }- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.}- (void)viewDidUnload{ [super viewDidUnload]; self.statusText = nil; // Release any retained subviews of the main view.}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } else { return YES; }}- (void)dealloc{ [statusText release]; [super dealloc];}@end
接着我们把这些代码与IB连接起来:
选择MainStoryboard_iphone.storyboard 右击View Controller Scene中的 Buton,选择Touch down与界面的
bottonPressed相连接:
接着将lable和statusText连接在一块:
最后运行程序,点击botton看看效果:
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
- IPhone学习笔记二-----处理基本交互
- 移动开发之iOS基础开发(二)实现基本的简单交互
- iOS学习笔记11-Xcode启动基本介绍
- ios学习笔记(二)
- ios 学习笔记(二)
- ios学习笔记(二)
- iOS开发3-实现基本交互
- IOS入门学习(二):在Xcode中创建工程
- Redis学习笔记二 CentOS下的基本操作
- XCode学习随笔03--iOS界面-抽屉式交互
- UE4学习笔记(二):c++与蓝图的交互
- openCV学习笔记(二)---openCV系列基本操作(2)
- ibatis学习笔记(二) 基本操作
- Shell学习笔记二(基本语法)
- Hibernate学习笔记(二)基本配置
- 1天学习1个类 UIBarButtomItem 类 示例
- UESTC Training for Graph Theory——M、Network
- [Android]自定义移动网络接入点
- 嵌入式系统设计师考试笔记之接口技术(转)
- java jdk和cglib动态代理
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- UESTC Training for Graph Theory——N、滑雪与时间胶囊(Large Input)
- 黑马程序员_学习日记29_winphone7开发_概述
- C#之电脑端口扫描器...
- 计算机存储
- 用一辈子去领悟的生活经典
- 黑马程序员_学习日记30_winphone7开发_项目的基本档案结构
- 二叉树的遍历
- 嵌入式系统设计师考试笔记之电子电路设计基础