[objective-c]按下按钮 KLCPopup 错误

发布时间: 2016/10/2 0:51:22
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

KLCPopup 图书馆有总是这些错误之一 (随机) 当我按下按钮我 KLCPopup 容器所载的观点之一︰

  1. NSInvalidArgumentException', reason: '-[NSISLinearExpression sendPlus:]
  2. (大多数时候)bad_access_exc code=1

这里是我的代码能够调用在 «FindViewController» KLCPopup

AddFeelingViewController *adf = [self.storyboard instantiateViewControllerWithIdentifier:@"AddFeelingView"];
adf.userTo = [_userFetch objectAtIndex:indexPath.row];
adf.controller = self;
adf.view.frame = CGRectMake(0.0, 0.0, 300.0, 250.0);

KLCPopup *popup = [KLCPopup popupWithContentView:[adf view] showType:KLCPopupShowTypeBounceIn dismissType:KLCPopupDismissTypeBounceOut maskType:KLCPopupMaskTypeDimmed dismissOnBackgroundTouch:YES dismissOnContentTouch:NO];

[popup show];

和这里我 «AddFeelingViewController» 中的代码︰

   - (void)viewDidLoad {

      super viewDidLoad];
      score = 0;

    if([_controller isKindOfClass:[FindViewController class]]){            
       _controller = (FindViewController*)_controller;     
    }else{
       _controller = (HomeViewController*)_controller;

    }

    - (IBAction)sendPlus:(id)sender { 
       score = 1;
    }
    - (IBAction)sendMinus:(id)sender {     
        score = -1;
    }
    - (IBAction)sendFeeling:(id)sender {

        if([_controller isKindOfClass:[FindViewController class]]){
             if(score !=0 ){
               [_controller addNewFriendship:_userTo andScore:score];
             }

        }else{
             //TODO
        }
     }

好在一切都链接在 storyboard 和它只有崩溃如果按钮链接。

你知道了?

解决方法 1:

我跑向你 n ° 2 作为同样的错误。 发生这种情况是因为你 AddFeelingViewController 是自动释放一次内部代码 FindViewController 执行。

AddFeelingViewController 在只 (体内的一种方法) 当前作用域中声明,所以电ARC释放它一次该方法已完成其执行。

若要解决这个问题,只是声明您 AddFeelingViewController 作为类变量 FindViewController

In FindViewController.m :

AddFeelingViewController *myAdfController;

@implementation FindViewController

-(void)displayMyAdf{
    myAdfController = [self.storyboard instantiateViewControllerWithIdentifier:@"AddFeelingView"];
    myAdfController.userTo = [_userFetch objectAtIndex:indexPath.row];
    myAdfController.controller = self;
    myAdfController.view.frame = CGRectMake(0.0, 0.0, 300.0, 250.0);

    KLCPopup *popup = [KLCPopup popupWithContentView:[myAdfController view] showType:KLCPopupShowTypeBounceIn dismissType:KLCPopupDismissTypeBounceOut maskType:KLCPopupMaskTypeDimmed dismissOnBackgroundTouch:YES dismissOnContentTouch:NO];

    [popup show];
}
官方微信
官方QQ群
31647020