我想通过点击显示UIViewController
MyViewControllerUICollectionViewCell
然后关闭它。
所以,在我的didSelectItemAtIndexPath中:
CGRect myFrame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
MyViewController *myController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
myController.view.frame = myFrame;
[self.view addSubview:myController.view];
有用!
在MyViewController我有UIButton
链接到:
- (IBAction)close:(id)sender {
[self.view removeFromSuperview];
}
但是当我点击按钮时,我有这个而不是关闭方法调用:
编辑:感谢calampunay和Manohar
问题解决了。但是我已将addSubview和removeFromSuperview都替换为 AppDelagate,其中将MyViewController声明为属性。原因是 - 我想关闭MyViewController即使我会跳转到其他选项卡(我的应用程序中有 TabBar)或其他东西。
即使我在其他地方(不是在它的框架中)点击MyViewController也会关闭会更好。