0
点赞
收藏
分享

微信扫一扫

崩溃预防处理 消息转发

新建NSObject分类

  - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector{
      //方法签名
      return  [NSMethodSignature signatureWithObjCTypes:"v@:"];
    }
 - (void)forwardInvocation:(NSInvocation *)anInvocation{
          NSLog(@"crash-----类:%@中 未实现该方法",NSStringFromClass([anInvocation.target             class]),NSStringFromSelector(anInvocation.selector));
    }

如下情况不会崩溃,会走消息转发机制打印信息

    UIButton *bbb = [UIButton buttonWithType:UIButtonTypeCustom];
    [bbb setTitle:@"xxxx" forState:UIControlStateNormal];
    bbb.frame = CGRectMake(100, 100, 100, 40);
    bbb.backgroundColor = [UIColor redColor];
    [self.view addSubview:bbb];
    [bbb addTarget:self action:@selector(xxxx) forControlEvents:UIControlEventTouchUpInside];

    [[NSObject new] performSelector:@selector(ffff)];
举报

相关推荐

0 条评论