我在视图控制器上有一个按钮,它提供了一个模态视图控制器。在viewcontroller的init方法中,我正在初始化一个UIImage视图,在它上面是一个自定义视图,在最后一个上面我有一个按钮(完成)。当我按下完成按钮时,我想要关闭模态视图控制器,我也想弹出初始视图控制器(呈现模态控制器的那个)。问题是我收到以下错误:
2014-04-21 19:31:16.223 Signature[5343:60b] -[UIImageView setEnableSetNeedsDisplay:]: unrecognized selector sent to instance 0x16d73550
以下是相关代码:
这是我实例化模态视图控制器时执行的操作:
- (void) onSignButtonPressed: (id)sender
{
PPSSignatureViewController *ppsSignatureViewController = [[[PPSSignatureViewController alloc] initWithNibName:nil bundle:nil documentViewController:self] autorelease];
ppsSignatureViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:ppsSignatureViewController animated:NO completion:^{
printf("done!!!");
}];
[self.navigationController popViewControllerAnimated:YES];
}
这是在实例化模态视图控制器时执行的代码:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil documentViewController:(MuDocumentController*)dController
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
EAGLContext * context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
PPSSignatureView *signatureView =
[[[PPSSignatureView alloc] initWithFrame:[[UIScreen mainScreen] bounds] context:context] autorelease];
signatureView.opaque = NO;
signatureView.backgroundColor = [UIColor clearColor];
UIGraphicsBeginImageContext(dController.view.bounds.size);
[dController.view drawViewHierarchyInRect:dController.view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *backView = [[UIImageView alloc] initWithImage:image];
signatureView.frame = backView.bounds;
UIButton *finishSignatureButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[finishSignatureButton addTarget:self
action:@selector(finishSignatureButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
[finishSignatureButton setTitle:@"Salveaza semnatura" forState:UIControlStateNormal];
finishSignatureButton.frame = CGRectMake(signatureView.frame.size.width - 210, signatureView.frame.size.height - 50, 200, 40.0);
finishSignatureButton.backgroundColor = [UIColor whiteColor];
[backView addSubview:finishSignatureButton];
self.view = backView;
self.view.backgroundColor = [UIColor clearColor];
[backView release];
[finishSignatureButton release];
[signatureView release];
[image release];
}
return self;
}
最后这是由finishSignatureButton触发的代码:
- (void) finishSignatureButtonPressed: (id)sender
{
printf("DOne");
[self.presentingViewController dismissViewControllerAnimated:YES completion: nil];
}
我需要知道我做错了什么?我是客观C编程的菜鸟。我尝试以多种方式解雇视图,其中没有一个成功...而且,我不知道我在做什么是正确的,如果订单没问题。在签名视图控制器的init方法中操作的顺序似乎很重要。任何帮助都感激不尽。
答案 0 :(得分:1)
我看到的最大问题是这一行:
self.view = backView;
您正在尝试使用UIImageView替换视图控制器的视图属性 - 这是不好的。不应以这种方式操纵视图控制器的视图属性。您应该为其添加子视图,而不是完全替换它。您的应用程序正在尝试在视图控制器的视图上调用(我假设的)方法(setEnableSetNeedsDisplay :)。由于您已将此替换为UIImageView实例,因此您将获得异常,因为UIImageView未实现此方法。
相反,做这样的事情:
[self.view addSubview:backView];
请注意,您也可以通过这种方式将任何其他子视图添加到视图中,因此您的按钮不必是图像的子视图,但它可以是视图控制器视图的直接子视图。