我正在开发拖放应用程序,当用户放下图像时,我想从它的拖放点复制它,然后原始图像返回到它的初始点。我决定在执行 touchesEnded 后将 uiimageview 添加到我的视图控制器中,
我有包含该方法的拖动视图类:
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint activePoint = [[touches anyObject] locationInView:self];
UIImageView *myimage;
myimage.image = self.image;
myimage.center = activePoint;
ViewController *cview ;
cview = [[ViewController alloc]init];
[cview getpoint: myimage];
}
现在在视图控制器中,这是 getpoint 选择器:
-(void) getpoint : (UIImageView *) mine{
UIImageView *newimage;
newimage = mine;
[self.view addSubview:newimage];
NSLog(@" in getpoint");
}
当我放下对象时,出现此错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
但是当我删除 addsubview 语句时,NSlog 是正确的
任何解决方案?