这次的学习的内容是关于在button动态方法连接多个switch 和textfield
2013-10-16 08:30
447 查看
目标:
这次的学习的内容是关于在button动态方法连接多个switch 和textfield, switch判定textfield的显示结果, 使用代码获取button动态方法,并且在interfaceBuilder内对button,switch和textfield进行动态交互连接,然后显示运行结果。
编码:
//
// ViewController.h
// hhhh
//
// Created by bitcar on 12-7-10.
// Copyright (c) 2012年 bitcar . All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface ViewController : UIViewController
{
IBOutlet UITextField *passwordlength;
IBOutlet UITextField *password;
IBOutlet UISwitch *includeUpperCase;
IBOutlet UISwitch *includeLowerCase;
IBOutlet UISwitch *includeNumbers;
}
@property (nonatomic, retain) UITextField *passwordlength;
@property (nonatomic, retain) UITextField *password;
@property (nonatomic, retain) UISwitch *includeUpperCase;
@property (nonatomic, retain) UISwitch *includeLowerCase;
@property (nonatomic, retain) UISwitch *includeNumbers;
//-(IBAction)setPassword:(id)sender;
- (IBAction)onPasswordButtonClick:(id)sender;
@end
#import "ViewController.h"
@implementation ViewController
@synthesize passwordlength, password;
@synthesize includeLowerCase, includeNumbers, includeUpperCase;
#define RANDOM_SEED() srandom(time(NULL))
//定义随机值,用最小值和最大值和随机数来计算,返回整数值
#define RANDOM_INT(_MIN_, _MAX_) ((_MIN_) +random() % ((_MAX_ +1) - (_MIN_)))
//控件输入返回判定方法
- (BOOL) textFieldShouldReturn: (UITextField*)textField
{
if(textField == password)
{
[password resignFirstResponder];//隐藏密码文本框输入的键盘
}
if(textField == passwordlength)
{
[passwordlength resignFirstResponder];//隐藏密码长度文本框输入的键盘
}
return YES;
}
//button方法,点击的密码显示在文本框里
//-(IBAction)setPassword:(id)sender
- (IBAction)onPasswordButtonClick:(id)sender
{
//输入密码长度
NSInteger iPasswordLength = [passwordlength.text intValue];
//打开字母小写
BOOL bIncludeLowerCase = includeLowerCase.on;
//打开字母大写
BOOL bIncludeUpperCase = includeUpperCase.on;
//打开数字
BOOL bIncludeNumbers = includeNumbers.on;
NSString *passwordText = @"";
//定义a到z字母
NSString *lowercaseChars
= @"abcdefghijklmnopqrstuvwxyz";
//定义A到Z字母
NSString *uppercaseChars
= @"ABCDEFGHIGKLMNOPQRSTUVWXYZ";
//定义数字
NSString *numbersChars = @"1234567890";
//随机变量
RANDOM_SEED();
//字符对象为空
NSString *passwordChars = @"";
//字母小写的条件语句
if(bIncludeLowerCase)
{
passwordChars =
[NSString stringWithFormat:@"%@%@",
passwordChars, lowercaseChars];
}
//字母大写的条件语句
if (bIncludeUpperCase) {
passwordChars =
[NSString stringWithFormat:@"%@%@",
passwordChars, uppercaseChars];
}
//字母为数字的条件语句
if (bIncludeNumbers) {
passwordChars =
[NSString stringWithFormat:@"%@%@",
passwordChars, numbersChars];
}
//数值从0开始,当数值小于密码长度,取得数字字符,获取的数据转换为文字格式
for (NSInteger i=0;
i<iPasswordLength; i++)
{
int index = RANDOM_INT(0,
[passwordChars length]-1);
NSRange range = NSMakeRange(index,1);
NSString *passwordChar = [passwordChars substringWithRange:range];
passwordText =
[NSString stringWithFormat:@"%@%@",
passwordText, passwordChar];
}
password.text = @"";
password.text = passwordText;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) dealloc
{
[passwordlength release];
[password release];
[includeNumbers release];
[includeLowerCase release];
[includeUpperCase release];
[super dealloc];
}
@end
运行程序:
当把所有字母大写小写和数字开启时。
当只把字母大写关闭时。
当把数字开启时。
总结:
@property (nonatomic, retain) UITextField *password;
//-(IBAction)setPassword:(id)sender;
这次的编码因为系统误认set,get的原因让程序不能执行,我将记录下并分析其中的原因。
当把“按扭生成密码“这个方法写成setPassword时,系统出现如下的警告:
原因是运行时程序将这个方法误认为set get。导致程序不能执行。
如果把它改成- (IBAction)onPasswordButtonClick:(id)sender;便没问题了。
代码学习:
写一个set 为string:
-(void) setPassword: (NSString)
{
[password release];
password = nill;
self.password = _password;
}
不返回值
-(NSString) getPassword
{
return password;
}
这次的学习的内容是关于在button动态方法连接多个switch 和textfield, switch判定textfield的显示结果, 使用代码获取button动态方法,并且在interfaceBuilder内对button,switch和textfield进行动态交互连接,然后显示运行结果。
编码:
//
// ViewController.h
// hhhh
//
// Created by bitcar on 12-7-10.
// Copyright (c) 2012年 bitcar . All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface ViewController : UIViewController
{
IBOutlet UITextField *passwordlength;
IBOutlet UITextField *password;
IBOutlet UISwitch *includeUpperCase;
IBOutlet UISwitch *includeLowerCase;
IBOutlet UISwitch *includeNumbers;
}
@property (nonatomic, retain) UITextField *passwordlength;
@property (nonatomic, retain) UITextField *password;
@property (nonatomic, retain) UISwitch *includeUpperCase;
@property (nonatomic, retain) UISwitch *includeLowerCase;
@property (nonatomic, retain) UISwitch *includeNumbers;
//-(IBAction)setPassword:(id)sender;
- (IBAction)onPasswordButtonClick:(id)sender;
@end
#import "ViewController.h"
@implementation ViewController
@synthesize passwordlength, password;
@synthesize includeLowerCase, includeNumbers, includeUpperCase;
#define RANDOM_SEED() srandom(time(NULL))
//定义随机值,用最小值和最大值和随机数来计算,返回整数值
#define RANDOM_INT(_MIN_, _MAX_) ((_MIN_) +random() % ((_MAX_ +1) - (_MIN_)))
//控件输入返回判定方法
- (BOOL) textFieldShouldReturn: (UITextField*)textField
{
if(textField == password)
{
[password resignFirstResponder];//隐藏密码文本框输入的键盘
}
if(textField == passwordlength)
{
[passwordlength resignFirstResponder];//隐藏密码长度文本框输入的键盘
}
return YES;
}
//button方法,点击的密码显示在文本框里
//-(IBAction)setPassword:(id)sender
- (IBAction)onPasswordButtonClick:(id)sender
{
//输入密码长度
NSInteger iPasswordLength = [passwordlength.text intValue];
//打开字母小写
BOOL bIncludeLowerCase = includeLowerCase.on;
//打开字母大写
BOOL bIncludeUpperCase = includeUpperCase.on;
//打开数字
BOOL bIncludeNumbers = includeNumbers.on;
NSString *passwordText = @"";
//定义a到z字母
NSString *lowercaseChars
= @"abcdefghijklmnopqrstuvwxyz";
//定义A到Z字母
NSString *uppercaseChars
= @"ABCDEFGHIGKLMNOPQRSTUVWXYZ";
//定义数字
NSString *numbersChars = @"1234567890";
//随机变量
RANDOM_SEED();
//字符对象为空
NSString *passwordChars = @"";
//字母小写的条件语句
if(bIncludeLowerCase)
{
passwordChars =
[NSString stringWithFormat:@"%@%@",
passwordChars, lowercaseChars];
}
//字母大写的条件语句
if (bIncludeUpperCase) {
passwordChars =
[NSString stringWithFormat:@"%@%@",
passwordChars, uppercaseChars];
}
//字母为数字的条件语句
if (bIncludeNumbers) {
passwordChars =
[NSString stringWithFormat:@"%@%@",
passwordChars, numbersChars];
}
//数值从0开始,当数值小于密码长度,取得数字字符,获取的数据转换为文字格式
for (NSInteger i=0;
i<iPasswordLength; i++)
{
int index = RANDOM_INT(0,
[passwordChars length]-1);
NSRange range = NSMakeRange(index,1);
NSString *passwordChar = [passwordChars substringWithRange:range];
passwordText =
[NSString stringWithFormat:@"%@%@",
passwordText, passwordChar];
}
password.text = @"";
password.text = passwordText;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) dealloc
{
[passwordlength release];
[password release];
[includeNumbers release];
[includeLowerCase release];
[includeUpperCase release];
[super dealloc];
}
@end
运行程序:
当把所有字母大写小写和数字开启时。
当只把字母大写关闭时。
当把数字开启时。
总结:
@property (nonatomic, retain) UITextField *password;
//-(IBAction)setPassword:(id)sender;
这次的编码因为系统误认set,get的原因让程序不能执行,我将记录下并分析其中的原因。
当把“按扭生成密码“这个方法写成setPassword时,系统出现如下的警告:
原因是运行时程序将这个方法误认为set get。导致程序不能执行。
如果把它改成- (IBAction)onPasswordButtonClick:(id)sender;便没问题了。
代码学习:
写一个set 为string:
-(void) setPassword: (NSString)
{
[password release];
password = nill;
self.password = _password;
}
不返回值
-(NSString) getPassword
{
return password;
}
相关文章推荐
- QT学习:根据数据库的内容动态添加Button
- Python分布式爬虫前菜(1):关于静态动态网页内容获取的N种方法
- android学习中关于Textview,Button,EditText,连接的设置,Intent,Activity不同状态等的一系列基础知识点
- 关于JS点击button之灵活替换改变内容方法
- 关于Struts2 namespace 的学习笔记(DMI动态方法调用)
- 关于C#静态方法与动态代码的核心代码学习
- QT学习:根据数据库的内容动态添加Button
- 【SSM学习笔记】动态生成jsp下拉框列表内容的一种方法
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
- c# 关于如何连接数据库的几种方法(switch语句中)
- 蚁群算法求解0/1背包,注意学习二维动态数组的初始化方法
- 关于linux中的动态连接
- WCF学习:关于数据类(DataContract)中逻辑方法或复写方法未被初始化的原因及解决方案
- 最近在ArcGIS Engine开发中关于调用gp工具过程出现COM 组件的调用返回了错误 HRESULT E_FAIL 错误的解决方法 和 学习oracle中遇到的一些问题总结
- 关于Unity3D中Resources动态加载NGUI图片的方法!!!
- 关于navicat连接oracle 报 ORA-12737 set CHS16GBK错误的解决方法
- 利用SQLConnection动态连接数据库的方法
- 学习笔记——关于动态绑定和属性初始化
- Spider网络爬虫学习——通过Get、Post方法直接抓取网页内容
- Android学习札记24:收集到的一些关于解决Bitmap OOM内存溢出的方法