Iphone开发基础教程 example4
来源:互联网 发布:部门预算软件 编辑:程序博客网 时间:2024/05/16 05:40
slider实现(必会)
1、在ViewController.xib文件中,从library中托出一个slider,一个label(并调整大小、文本)
2、在ViewController.h文件中,添加sliderLabel变量和它的@property方法,添加方法sliderChanged
#import <UIKit/UIKit.h>@interface ViewController : UIViewController{ IBOutlet UILabel *sliderLabel;}@property(retain,nonatomic) UILabel *sliderLabel;-(IBAction)sliderChanged:(id)sender;@end3、在ViewController.m文件实现sliderChanged方法 及 @synthesize方法
#import "ViewController.h"@implementation ViewController@synthesize sliderLabel;-(IBAction)sliderChanged:(id)sender{ //NSLog(@"sliderChanged"); UISlider *slider = (UISlider *)sender; int progressAsInt = (int)(slider.value); NSString * newText = [[NSString alloc] initWithFormat:@"%d",progressAsInt]; sliderLabel.text = newText; [newText release];}4、回到xib文件中,Control键并从File‘s Owner拖动到标签,然后选择sliderLabel;
选中slider,打开connection,将value changed后的加号连接到File's Owner,选择sliderChanged
5、运行,看效果
在文本框输完字符后,点击Done,隐藏软键盘
1、头文件中,增加方法;在实现文件中,实现该方法
-(IBAction)textFieldDoneEditing:(id)sender;
-(IBAction)textFieldDoneEditing:(id)sender{ NSLog(@"textFieldDoneEditing"); [sender resignFirstResponder];}
2、xib文件中,选中文本框,打开connection 拖Did end on Exit后边的圆圈到File's Owner,选择textFieldDoneEditing
3、运行,看效果
按钮实现(必会)
1、在ViewController.xib文件中添加一个按钮
2、在ViewController.h文件中,
@property(retain,nonatomic) UIButton *doSomethingButton;
-(IBAction)doSomething:(id)sender;3、在ViewController.m文件中,实现
@synthesize doSomethingButton;
-(IBAction)doSomething:(id)sender{ UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure?" delegate:self cancelButtonTitle:@"No way" destructiveButtonTitle:@"Yes,I'm Sure" otherButtonTitles:nil]; [actionSheet showInView:self.view]; [actionSheet release]; }-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{ if(!buttonIndex ==[actionSheet cancelButtonIndex]) { NSString *msg = nil; if(nameField.text.length>0) msg = [[NSString alloc] initWithFormat:@"You can breathe easy,%@,everything went OK",nameField.text]; else msg = @"You can breathe easy,everything went OK"; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Something was done" message:msg delegate:self cancelButtonTitle:@"Phew!" otherButtonTitles:nil]; [alert show]; [alert release]; [msg release]; }}4、运行看效果
- Iphone开发基础教程 example4
- 《iPhone 开发基础教程》
- iPhone 开发基础教程
- Iphone开发基础教程 example3
- iPhone开发基础教程 笔记
- 强烈推荐iPhone 3开发基础教程
- 《iPhone 4开发基础教程》读书笔记
- iPhone 4与iPad开发基础教程
- Iphone开发基础教程 example5 自动旋转
- Iphone开发基础教程 example6 多视图应用
- iPhone开发四剑客之《Objective-C基础教程》
- 《Iphone开发基础教程》第五章 自动旋转和调整大小
- <<Iphone开发基础教程》第十章应用程序设置和用户默认设置
- Iphone开发基础教程 example1 单击按钮弹出提示框
- Iphone开发基础教程 (8章 表视图)--读书笔记
- Iphone开发基础教程 (10章 应用程序设置)--读书笔记
- 《Iphone开发基础教程》第五章 自动旋转和调整大小
- Iphone开发基础教程 (11章 基本数据持久性)--读书笔记
- 用Nircmd轻松复制文件(文件夹)的完整路径
- usaco:Cow Pedigrees
- 复数类中运算符重载(第八周任务一)
- ListView之setEmptyView的问题
- Solr安装异常:SolrException: Error loading class 'solr.VelocityResponseWriter'
- Iphone开发基础教程 example4
- 菜鸟学堂 -【Python Socket 】
- Oracle查询永久表空间使用情况
- Failed to fectch URl https://dl-ssl.google.com/android/repository/addons_list.xml, reason: Connectio
- UVA 10300 - Ecological Premium
- 六大原则之“迪米特法则(LoD)“笔记
- Java源码分析 – ArrayList动态数组列表源码分析
- 35 岁前程序员要规划好的四件事
- Ubuntu 修改hosts