ios - 按下按钮时 KLCPopup 错误

标签 ios objective-c uiview

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)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中的所有内容都链接良好,只有在链接按钮时才会崩溃。

你有什么想法吗?

最佳答案

我遇到了与你的 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/

相关文章:

ios - 我应该在哪里释放组队列?

ios - 如何在 iPhone 6/6 plus 上使 UITableViewCells 具有相同的高度?

iphone - 这两个 NSString 方法之间的区别

ios - 具有自动布局约束的 UIView 动画变化

ios - 如何在 Swift 中将数据从一个 TableView 传递到另一个 TableView ?

iphone - 应用程序中无法识别的选择器 didFinishLaunchingWithOptions 与 topViewController 分配

ios - 未找到 <TargetName-Swift.h> 文件

ios - NSTask 不适用于具有特殊字符的文件路径

iphone - 在 IB 中,如何让 subview 在调整父级大小时保持与其父级相同的大小?

ios - swift uiview 没有名为 center 的成员