block的简单使用

今天用到了下面个方法:

presentViewController:animated:completion:
Presents a view controller.

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
Parameters
viewControllerToPresent
The view controller being presented.
flag
Pass YES to animate the presentation; otherwise, pass NO.
completion
A completion handler or NULL.
Discussion
On iPhone and iPod touch, the presented view is always full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.

This method sets the presentedViewController property to the specified view controller, resizes that view controller’s view and then adds the view to the view hierarchy. The view is animated onscreen according to the transition style specified in the modalTransitionStyle property of the presented view controller.

The completion handler is called after the viewDidAppear: method is called on the presented view controller.


以前没用过block,就临时学了一下

block的定义:

    int (^myBlock) (int a,int b) = ^(int a,int b){  
           return a+b;  
       };  

    void (^myBlock) (void) = ^(void){  
           dosomething;  
       };  

空参数可以这样写:

 void (^myBlock) () = ^{  
           dosomething;  
       };  

但是前面的括号不能少。当然代码短的话,直接使用匿名的就行了。

调用:myBlock(1,2);

myBlock();



block 数组

    void (^blocks[2])(void) = {  
        ^(void){ NSLog(@" >> This is block 1!"); },  
        ^(void){ NSLog(@" >> This is block 2!"); }  
    };  
      
    blocks[0]();  
    blocks[1]();  

刚详细的可以参考

http://blog.csdn.net/kesalin/article/details/6721481

你可能感兴趣的:(ios开发,Mac开发,objective-c)