IOS宏定义 + 通告机制 + 强制MySQL区分大小写

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'等字段筛选出来了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值