1、宏定义一个NSURL
#define STR "abc"
2、利用通知传递字符串消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(doSomeThing)
name:@“XXX” object:要传递的对象];
后面的参数object就是传对象的,在之后的selector中是这样写的
- (void)doSomeThing:(NSNotification *)notification
=====================================================================
notification有三个方法
- (NSString *)name 通告标识
- (id)object 使用object方法可以获取对象
一般object都是指向poster(为了让observer在接受到notification时可以回调到poster)
-(NSDictionary*)userInfo 可以传递额外信息
//nil起通配作用,作为name参数时不管通知中心发送的通告名称是什么,观察器都会收到。
作为name和object参数时,观察器会收到所有通知。
一般在viewWillAppear中添加通知监听对象,在viewWillDisappear中清除通知。
比如键盘弹出和隐藏时触发的事件可以用通知来实现:
/*================================================================================
设置点击键盘时registerSV上滑
================================================================================*/
-(void)viewWillAppear:(BOOL)animated
{
//添加两个通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UITextFieldTextDidBeginEditingNotification//触发时间机制很重要
object:self.view.window];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
}
//当键盘弹出时
-(void)keyboardDidShow: (NSNotification *)notification
{
if([registerNameTF isEditing]==YES ||[registerAgeTF isEditing] ==YES)
{
return;
}
[UIView animateWithDuration:0.2
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^()
{
registerSV.frame=CGRectMake(9, 55-80, 311, 400);
}
completion:^(BOOL finished)
{
} ];
}
-(void)keyboardDidHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^()
{
registerSV.frame=CGRectMake(9, 55, 311, 400);
}
completion:^(BOOL finished)
{
} ];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
//清除通知
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
//是否符合要求状态显示
if(textField==registerNameTF)
{
showImageView1.alpha = 0;
}
else if(textField==registerAgeTF)
{
showImageView2.alpha = 0;
}
else if(textField==registerEmailTF)
{
showImageView3.alpha = 0;
}
else if(textField==registerCodeTF)
{
showImageView4.alpha = 0;
}
else if(textField==registerConfirmCodeTF)
{
showImageView5.alpha = 0;
}
}
=====================================================================
3、强制让MYSQL比较字符串时区分大小写
可以在字符串字段前面加上 binary关键字。
如
where name = binary 'lu'就不会把name=‘Lu’和name='LU'等字段筛选出来了。
#define STR "abc"
2、利用通知传递字符串消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(doSomeThing)
name:@“XXX” object:要传递的对象];
后面的参数object就是传对象的,在之后的selector中是这样写的
- (void)doSomeThing:(NSNotification *)notification
=====================================================================
notification有三个方法
- (NSString *)name 通告标识
- (id)object 使用object方法可以获取对象
一般object都是指向poster(为了让observer在接受到notification时可以回调到poster)
-(NSDictionary*)userInfo 可以传递额外信息
//nil起通配作用,作为name参数时不管通知中心发送的通告名称是什么,观察器都会收到。
作为name和object参数时,观察器会收到所有通知。
一般在viewWillAppear中添加通知监听对象,在viewWillDisappear中清除通知。
比如键盘弹出和隐藏时触发的事件可以用通知来实现:
/*================================================================================
设置点击键盘时registerSV上滑
================================================================================*/
-(void)viewWillAppear:(BOOL)animated
{
//添加两个通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UITextFieldTextDidBeginEditingNotification//触发时间机制很重要
object:self.view.window];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
}
//当键盘弹出时
-(void)keyboardDidShow: (NSNotification *)notification
{
if([registerNameTF isEditing]==YES ||[registerAgeTF isEditing] ==YES)
{
return;
}
[UIView animateWithDuration:0.2
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^()
{
registerSV.frame=CGRectMake(9, 55-80, 311, 400);
}
completion:^(BOOL finished)
{
} ];
}
-(void)keyboardDidHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^()
{
registerSV.frame=CGRectMake(9, 55, 311, 400);
}
completion:^(BOOL finished)
{
} ];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
//清除通知
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
//是否符合要求状态显示
if(textField==registerNameTF)
{
showImageView1.alpha = 0;
}
else if(textField==registerAgeTF)
{
showImageView2.alpha = 0;
}
else if(textField==registerEmailTF)
{
showImageView3.alpha = 0;
}
else if(textField==registerCodeTF)
{
showImageView4.alpha = 0;
}
else if(textField==registerConfirmCodeTF)
{
showImageView5.alpha = 0;
}
}
=====================================================================
3、强制让MYSQL比较字符串时区分大小写
可以在字符串字段前面加上 binary关键字。
如
where name = binary 'lu'就不会把name=‘Lu’和name='LU'等字段筛选出来了。