本次的学习的内容是关于在button动态方法连接多个switch 和textfield
目标:
//
//
//
//
//
//
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface ViewController : UIViewController
{
}
@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
{
return YES;
}
//button方法,点击的密码显示在文本框里
//-(IBAction)setPassword:(id)sender
- (IBAction)onPasswordButtonClick:(id)sender
{
//数值从0开始,当数值小于密码长度,取得数字字符,获取的数据转换为文字格式
for (NSInteger i=0; i<iPasswordLength; i++)
{
}
password.text = @"";
password.text = passwordText;
}
- (void)viewDidLoad
{
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
}
- (void) dealloc
{
}
@end
当把所有字母大写小写和数字开启时。
当只把字母大写关闭时。
当把数字开启时。
//-(IBAction)setPassword:(id)sender;
这次的编码因为系统误认set,get的原因让程序不能执行,我将记录下并分析其中的原因。
当把“按扭生成密码“这个方法写成setPassword时,系统出现如下的警告:
原因是运行时程序将这个方法误认为set get。导致程序不能执行。
如果把它改成- (IBAction)onPasswordButtonClick:(id)sender;便没问题了。