Ios 动态UIButton lldb崩溃
因此,我正在创建按钮并用它们填充视图:Ios 动态UIButton lldb崩溃,ios,iphone,objective-c,uibutton,Ios,Iphone,Objective C,Uibutton,因此,我正在创建按钮并用它们填充视图: -(void) generateAnimalsForView:(UIView *)view withAnimals:(NSString *)animalName animalCount:(int)count { animalsView = view; //get size of main view int viewWidth = view.frame.size.width - animalWidth; int vi
-(void) generateAnimalsForView:(UIView *)view withAnimals:(NSString *)animalName animalCount:(int)count
{
animalsView = view;
//get size of main view
int viewWidth = view.frame.size.width - animalWidth;
int viewHeight = view.frame.size.height - animalHeight;
if (count > maxCountOfAnimals)
count = maxCountOfAnimals;
if (count > 0){
UIButton *initialView = [[UIButton alloc] initWithFrame:CGRectMake(animalWidth+arc4random() % (int)viewWidth, animalHeight+arc4random() % (int)viewHeight, animalWidth, animalHeight)];
[initialView setTag:100];
[initialView addTarget:self action:@selector(setAnimationForRunning:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[initialView setBackgroundImage:[UIImage imageNamed:@"animal"] forState:UIControlStateNormal];
[view addSubview:initialView];
int numViews = 0;
while (numViews < count-1) {
BOOL goodView = YES;
UIButton *candidateView = [[UIButton alloc] initWithFrame:CGRectMake(arc4random() % (int)viewWidth, arc4random() % (int)viewHeight, animalWidth, animalHeight)];
[candidateView setTag:100+numViews+1];
[candidateView addTarget:self action:@selector(setAnimationForRunning:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[candidateView setBackgroundImage:[UIImage imageNamed:@"animal"] forState:UIControlStateNormal];
for (UIButton *placedView in view.subviews) {
if (CGRectIntersectsRect(CGRectInset(candidateView.frame, 5+arc4random()%5, 5+arc4random()%5), placedView.frame)) {
goodView = NO;
break;
}
}
if (goodView) {
[view addSubview:candidateView];
numViews += 1;
}}
}
}
它在main方法上停止
我的setAnimationForRunning方法:
编辑2:
所以问题是,我的模型类中有这个方法,当我试图使用VC中的这个类创建带有动作的按钮时,它会因为错误lldb而崩溃
AnimalsModel *animalsModel = [[AnimalsModel alloc] init];//model for math and stuff
[animalsModel generateAnimalsForView:animalsView withAnimals:@"animal" animalCount:(int)fResultWeight];
但当我在VC中创建相同的方法并使用它时:
[self generateAnimalsForView:animalsView withAnimals:@"animal" animalCount:(int)fResultWeight];
按钮被创建,一切都完美地工作。有人能给我解释一下为什么会这样吗?谢谢在您的问题中添加准确完整的错误信息。而且它肯定会在特定行上崩溃?您不使用UIControlEventTouchUpInside作为按钮有什么原因吗?不,只是测试它如何与UIControlEventTouchDownenable异常断点一起工作,并查看您的应用程序崩溃的确切位置。
AnimalsModel *animalsModel = [[AnimalsModel alloc] init];//model for math and stuff
[animalsModel generateAnimalsForView:animalsView withAnimals:@"animal" animalCount:(int)fResultWeight];
[self generateAnimalsForView:animalsView withAnimals:@"animal" animalCount:(int)fResultWeight];