与 KLCPopup library 当我按下 KLCPopup 容器中包含的 View 按钮之一时,我总是出现以下错误之一(随机):
NSInvalidArgumentException',原因:'-[NSISLinearExpression sendPlus:]
- (大多数时候)
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/