1.ios的协议

ios的协议类似Java里的接口,起用法是一模一样的,目前只理解到这儿,以后有了新的理解在补充,基本用法如下:

1 @protocol BlueInterface
2 
3 - (void) foundDevice:(CBPeripheral *) cbPeripheral;
4 - (void) disconnectDevicw:(CBPeripheral *) cbPeripheral;
5 
6 @end
1 @interface BlueUtil : NSObject <CBCentralManagerDelegate,CBPeripheralDelegate>
2 {
3     CBCentralManager *m_blueManager;
4 }
5 
6 + (BlueUtil *) getInstance;
7 
8 @property (nonatomic,assign) id <BlueInterface> delegate;
9 @end

以上只是声明,其调用方法如下:

1 - (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
2 {    
3     [delegate foundDevice:peripheral];
4 }
5 
6 - (void) centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
7 {
8     [delegate disconnectDevicw:peripheral];
9 }

实现该协议:

1 @interface ViewController : UITableViewController<BlueInterface>

2.ios多参数的定义:

1 - (id) initwithContent:(NSString *)_titile author:(NSString *)_author ids:(NSString *)_ids pullDate:(NSString *)_pullDate ;

3.ios键盘的弹出,在这里主要是做了界面适配,使用了约束,就写一下约束下键盘弹出的代码:

1 @interface TweetDetailViewControl : UIViewController <ASIHTTPRequestDelegate,ViewProtocol>
2 
3 @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
4 
5 @end

这个是UITextView相对于UIView底部的约束

 1     [[NSNotificationCenter defaultCenter]
 2         addObserver:self
 3            selector:@selector(keyboadWillShow:)
 4                name:UIKeyboardWillShowNotification
 5              object:nil];
 6     [[NSNotificationCenter defaultCenter]
 7         addObserver:self
 8            selector:@selector(keyboardWillHide:)
 9                name:UIKeyboardWillHideNotification
10              object:nil];

注册键盘弹出隐藏的方法

 1 - (void)keyboadWillShow:(NSNotification*)note
 2 {
 3     NSDictionary *info = [note userInfo];
 4     NSValue *kbFrame = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
 5     
 6     NSTimeInterval animationDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
 7     CGRect keyboardFrame = [kbFrame CGRectValue];
 8     
 9     CGRect finalKeyboardFrame = [self.view convertRect:keyboardFrame fromView:self.view.window];
10     
11     int kbHeight = finalKeyboardFrame.size.height;
12     
13     int height = kbHeight + self.bottomConstraint.constant;
14     
15     self.bottomConstraint.constant = height;
16     
17     [UIView animateWithDuration:animationDuration animations:^{
18         [self.view layoutIfNeeded];
19     }];
20 }
21 
22 - (void)keyboardWillHide:(NSNotification*)note
23 {
24     NSDictionary *info = [note userInfo];
25     
26     NSTimeInterval animationDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
27     
28     self.bottomConstraint.constant = 10;
29     
30     [UIView animateWithDuration:animationDuration animations:^{
31         [self.view layoutIfNeeded];
32     }];
33 }

4.UItextView设置边框:

1     m_textView.layer.borderColor = UIColor.grayColor.CGColor;
2     m_textView.layer.borderWidth = 1;
3     m_textView.layer.cornerRadius = 6;
4     m_textView.layer.masksToBounds = YES;

5.从storyboard加载ViewControl

1 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
2 
3     UIViewControl *tweetDetail = [storyboard instantiateViewControllerWithIdentifier:@"TweetDetailViewControl"];

6.ios7以后UITableView被遮住一部分:

1     if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
2         self.edgesForExtendedLayout = UIRectEdgeNone;
3         self.automaticallyAdjustsScrollViewInsets = NO;
4     }

8.ios单例:

 1 + (BlueUtil *) getInstance
 2 {
 3     static BlueUtil *blueUtil = nil;
 4     
 5     static dispatch_once_t onceToken;
 6     dispatch_once(&onceToken, ^{
 7         blueUtil = [[self alloc] init];
 8     });
 9     
10     
11     return blueUtil;
12 }

 9.ARC混编

在我们开发ios项目时一般默认启用了ARC模拟,但有时候我们使用一些开源的框架时,就要用到混编,我用到的有TBXML,ASIHttpRequest

在这里直接截一张图吧: