OGeek|极客世界-中国程序员成长平台

标题: ios - 按下按钮时出现 KLCPopup 错误 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:35
标题: ios - 按下按钮时出现 KLCPopup 错误

KLCPopup library 当我按下 KLCPopup 容器中包含的 View 按钮之一时,我总是(随机)出现以下错误之一:

  1. NSInvalidArgumentException',原因:'-[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)sendPlusid)sender { 
       score = 1;
    }
    - (IBAction)sendMinusid)sender {     
        score = -1;
    }
    - (IBAction)sendFeelingid)sender {

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

        }else{
             //TODO
        }
     }

Storyboard 中的所有内容都链接得很好,只有在链接按钮时才会崩溃。

你有什么想法吗?



Best Answer-推荐答案


我遇到了与您的 n°2 完全相同的错误。 发生这种情况是因为一旦执行 FindViewController 中的代码,您的 AddFeelingViewController 就会自动释放。

您的 AddFeelingViewController 仅在当前范围内(在方法的主体中)声明,因此一旦方法完成执行,ARC 就会释放它。

要解决这个问题,只需将您的 AddFeelingViewController 声明为 FindViewController 的类变量。

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];
}

关于ios - 按下按钮时出现 KLCPopup 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26841410/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4