我有一个扩展 UIImageView 的 UIImageCustom 对象,在这个类的一个方法中,我想获取 ViewController 的实例,我的对象 UICustom 被添加到其中。
在我的 UIImageCustom 类的 touchesBegan 方法中,当我触摸 UIImage 时,我想在我的 ViewController 中添加其他 UIImage:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UIImageView* newImageView=[[UIImageView alloc] initWithFrame:CGRectMake(60, 200, 200, 200)];
//Here I need add newImageView in my ViewController
[??? addSubview:newImageView];
}
有人可以帮助我吗?
最佳答案
如果您想按照自己的意愿行事,则必须向 UIImageCustom 类添加自定义属性,该类包含对所有者 View Controller 的引用。但还有更好的方法。
我建议您应该做的是在拥有该 View 的 View Controller 中实现 touchesBegan,并在那里执行任何自定义逻辑。
关于ios - 如何从 subView 开始获取 ViewController 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20335099/