[学习笔记]iphone学习小技巧

1. 版本控制 -- 是否响应某个方法 、查看当前系统版本。

   eg:

[self respondsToSelector:@Selector(presentModalViewController:animated:)]//Yes:表示响应这个方法
[[UIDevice currentDevice].systemVersion floatValue] < 7.0 //判断当前系统是否小于7.0

 

2. 模态视图动画设置

   eg:

ModalViewController *modalVC = [[ModalViewController alloc] init];
modalVC.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:modalVC animated:YES completion:^
}];

 

3. 通知中心使用

  eg:

//1. 声明一个NSNotificationCenter,并添加其操作和名字
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLabelText:) name:@"NotificationChangeLabelText" object:Nil];

//2. 实现通知中心执行的操作
-(void) changeLabelText:(NSNotification *)notification
{
    id text = notification.object;
    UILabel *label = (UILabel *)[self.view viewWithTag:102];
    label.text = text;
    [label sizeToFit];
}

//3. 在需要使用该通知的时候,调用此方法将参数_textField.text发送给 此通知中心
[[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationChangeLabelText" object:_textField.text];

//4. 在dealloc方法里面释放该通知
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"NotificationChangeLabelText" object:nil];

 

 

posted @ 2014-04-29 00:13  路就在脚下  Views(166)  Comments(0)    收藏  举报