使用 KLCPopup library 当我按下KLCPopup容器中包含的其中一个按钮时,我总是会出现其中一个错误(随机):
NSInvalidArgumentException', reason: '-[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
}
}
故事板中的所有内容都很好地链接,如果按钮被链接,它只会崩溃。
有你的想法吗?
答案 0 :(得分:2)
我遇到与你的n°2完全相同的错误。
发生这种情况是因为执行AddFeelingViewController
内的代码后,FindViewController
会自动释放。
您的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];
}