分享回调ios
iOS回调
2016-03-03 20:30:33 iteye_10820 阅读数 32

回调的简单使用,留一个笔记,方便以后查找

 

1,定义blocktypedefvoid(^signedRightJson)();

             typedef void(^signedErrorJson)();

2,定义的中复制

 

-(void)performActionWithCompletion:(signedRightJson)completion{

   

    completion();

    

 

}

3,调用

   BlockDemo *bd= [[BlockDemoalloc]init];

        [bd performActionWithCompletion:^{

    

            

            NSLog(@"%@",d.price);

            

 

        }];

 

 

 

 

完整代码:

 

typedef void(^signedRightJson)();
typedef void(^signedErrorJson)();

@interface BlockDemo : NSObject


//定义方法
-(void)performActionWithCompletion:(signedRightJson) completion;

@end



#import "BlockDemo.h"

@implementation BlockDemo

-(void)performActionWithCompletion:(signedRightJson)completion{
   
    completion();
    
}

@end




BlockDemo *bd= [[BlockDemo alloc]init];
        [bd performActionWithCompletion:^{
    
            
            NSLog(@"%@",d.price);
            
        }];

 

 

 

iOS回调
2013-06-06 09:42:01 majiakun1 阅读数 462

1.delegate

2.NSNotifcationCenter

3.@selector

IOS回调
2015-12-02 12:22:13 talking12391239 阅读数 427

在iOS 的设计中,至少存在两种方式的回调实现,一种是delegate,一种是CodeBlocks. 

blocks和delegate都含有转发并执行的逻辑;

blocks适合小而常用的逻辑,比如action,animation,

delegate适合重量级的转发,比如UIViewController之间的...,一般一个delegate涉及的接口会比较多。

delegate和block示例

DemoView.h

@protocol DemoViewDelegate <NSObject>


- (void)delegateApiOne:(id)sender;

@property (copy, nonatomic) void (^testBlock)(BOOL success);

@end


@interface DemoView


@property (weak, nonatomic) id<DemoViewDelegate> delegate;

@property (copynonatomicvoid (^testBlock)(BOOL success);

@end



DemoView.m

@interface DemoView ()


//@property (strong, nonatomic) UIImage* testImage;


@end


@implementation DemoView


#pragma mark - private method


- (void)callDelegateApi:(id)sender {

    if ([self.delegate respondsToSelector:@selector(delegateApiOne:)]) {

        [self.delegate delegateApiOne];

    }

}

@end


ImplementDelegate.m

#import "DemoView.h"


@interface ImplementDelegate () <DemoViewDelegate>

@property (strong, nonatomic) DemoView* demoView;

@end


@implementation ImplementDelegate

#pragma mark - DemoViewDelegate


- (void)refreshBtnDidClicked:(id)sender {

    //todo

}


#pragma mark - private method


- (void)callBlock{

demoView.testBlock = ^(BOOL show) {

            NSLog(@"result = %d", success);

        };

}


@end

2016-05-09 11:41:08 huanghuanghonghong 阅读数 167
[谈谈iOS上的回调   简书]http://www.jianshu.com/p/d78d3e4a21b3
2015-03-21 11:22:00 weixin_30343157 阅读数 1

iOS中使用系统的邮件、短信分享之后,如果该页面是禁止转屏的,那么可能不会出现问题,如果是设置为允许转屏,那么如果你的- (NSUInteger)supportedInterfaceOrientations
方法返回值不是UIInterfaceOrientationMaskAll,那么可能会报Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

我们只需把这个返回值设为UIInterfaceOrientationMaskAll即可解决。

 

转载于:https://www.cnblogs.com/fookehi/p/4355308.html

iOS回调之selector

阅读数 529

站位

博文 来自: jiahui220

iOS异步回调

阅读数 10

分享 iOS

阅读数 357

没有更多推荐了,返回首页