Ios 如何以编程方式添加UI/视图控制器?
我试图在点击UIView时加载ViewController,但我一直收到一个错误 ***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“情节提要()不包含标识符为“CameraVC3”的视图控制器 我认为这是因为没有正确地将ViewController添加到我的故事板中,所以我尝试用编程的方式来实现它,但它仍然没有被识别 视图控制器Ios 如何以编程方式添加UI/视图控制器?,ios,swift,viewcontroller,Ios,Swift,Viewcontroller,我试图在点击UIView时加载ViewController,但我一直收到一个错误 ***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“情节提要()不包含标识符为“CameraVC3”的视图控制器 我认为这是因为没有正确地将ViewController添加到我的故事板中,所以我尝试用编程的方式来实现它,但它仍然没有被识别 视图控制器 class ViewController: UIViewController, UIScrollViewDelega
class ViewController: UIViewController, UIScrollViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate{
let rect1 = CGRectMake(100, 60, 40, 60)
let captureButton2 = UIView(frame: rect1)
captureButton2.backgroundColor = UIColor.blueColor()
scrollView.addSubview(captureButton2)
captureButton2.addGestureRecognizer(UITapGestureRecognizer(target: self,
action: Selector("didTapImageView:")))
func didTapImageView(tap: UITapGestureRecognizer){
let captureDetails = storyboard!.instantiateViewControllerWithIdentifier("CameraVC3")! as! CameraVC3
presentViewController(captureDetails, animated: true, completion: nil)
}
class CameraVC3: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate{
override func viewWillAppear(animated: Bool) {
println("camera vc3 view will appear")
super.viewWillAppear(animated)
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "capture:"))
}
func capture() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
var imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.mediaTypes = [kUTTypeImage]
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}
摄像机控制器
class ViewController: UIViewController, UIScrollViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate{
let rect1 = CGRectMake(100, 60, 40, 60)
let captureButton2 = UIView(frame: rect1)
captureButton2.backgroundColor = UIColor.blueColor()
scrollView.addSubview(captureButton2)
captureButton2.addGestureRecognizer(UITapGestureRecognizer(target: self,
action: Selector("didTapImageView:")))
func didTapImageView(tap: UITapGestureRecognizer){
let captureDetails = storyboard!.instantiateViewControllerWithIdentifier("CameraVC3")! as! CameraVC3
presentViewController(captureDetails, animated: true, completion: nil)
}
class CameraVC3: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate{
override func viewWillAppear(animated: Bool) {
println("camera vc3 view will appear")
super.viewWillAppear(animated)
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "capture:"))
}
func capture() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
var imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.mediaTypes = [kUTTypeImage]
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}
要使用
UIStoryboard
的instantialeviewcontrollerwhithidentifier
方法,必须设置视图控制器的标识符以匹配作为标识符传递的字符串
序列图像板上的视图控制器可以从identity inspector设置其标识符(与为视图控制器设置自定义类的位置相同):
在“情节提要ID”框中,只需填写一个要用作此视图控制器标识的字符串。在这种情况下,将
CameraVC3
放入该框。为了使用UIStoryboard
的实例化控件的标识符方法,必须设置视图控制器的标识符以匹配作为标识符传递的字符串
序列图像板上的视图控制器可以从identity inspector设置其标识符(与为视图控制器设置自定义类的位置相同):
在“情节提要ID”框中,只需填写一个要用作此视图控制器标识的字符串。在这种情况下,将CameraVC3
放入该框。为了使用UIStoryboard
的实例化控件的标识符方法,必须设置视图控制器的标识符以匹配作为标识符传递的字符串
序列图像板上的视图控制器可以从identity inspector设置其标识符(与为视图控制器设置自定义类的位置相同):
在“情节提要ID”框中,只需填写一个要用作此视图控制器标识的字符串。在这种情况下,将CameraVC3
放入该框。为了使用UIStoryboard
的实例化控件的标识符方法,必须设置视图控制器的标识符以匹配作为标识符传递的字符串
序列图像板上的视图控制器可以从identity inspector设置其标识符(与为视图控制器设置自定义类的位置相同):
在“情节提要ID”框中,只需填写一个要用作此视图控制器标识的字符串。在这种情况下,将CameraVC3
放入该框。与以下行一起:
let captureDetails = storyboard!.instantiateViewControllerWithIdentifier("CameraVC3")! as! CameraVC3
您需要为故事板中的ViewController指定一个标识符名称“CameraVC3”。您可以在identity inspector中的序列图像板ID
字段中设置此项,行为:
let captureDetails = storyboard!.instantiateViewControllerWithIdentifier("CameraVC3")! as! CameraVC3
您需要为故事板中的ViewController指定一个标识符名称“CameraVC3”。您可以在identity inspector中的序列图像板ID
字段中设置此项,行为:
let captureDetails = storyboard!.instantiateViewControllerWithIdentifier("CameraVC3")! as! CameraVC3
您需要为故事板中的ViewController指定一个标识符名称“CameraVC3”。您可以在identity inspector中的序列图像板ID
字段中设置此项,行为:
let captureDetails = storyboard!.instantiateViewControllerWithIdentifier("CameraVC3")! as! CameraVC3
您需要为故事板中的ViewController指定一个标识符名称“CameraVC3”。您可以在identity inspector中的字段序列图像板ID
中设置此选项。处理所有这些问题的另一种方法是使用segues。连接interface builder中的视图控制器并命名分段。然后您可以使用self.performsguewithidentifier(“yourSegueName”,sender:self)
另一种处理这一切的方法是使用segues。连接interface builder中的视图控制器并命名分段。然后您可以使用self.performsguewithidentifier(“yourSegueName”,sender:self)
另一种处理这一切的方法是使用segues。连接interface builder中的视图控制器并命名分段。然后您可以使用self.performsguewithidentifier(“yourSegueName”,sender:self)
另一种处理这一切的方法是使用segues。连接interface builder中的视图控制器并命名分段。然后您可以使用self.performsguewithidentifier(“yourSegueName”,发件人:self)
谢谢您的及时回复!但是如何添加多个视图控制器?一旦我将Class
框从ViewController
更改为CameraVC3
,我的应用程序将不再加载ViewController
,并在加载屏幕上停止。是。因此,从对象库中拖动另一个:您不应该更改类,应该更改唯一标识符。您可能希望在故事板中定义多个视图控制器。不,不是。实际上没有任何等价物。。。在StackExchange评论中没有一个简单的方法来解释它。Ray Wenderlich应该有很好的故事板教程。我会处理好的。谢谢你的及时回复!但是如何添加多个视图控制器?一旦我将Class
框从ViewController
更改为CameraVC3
,我的应用程序将不再加载ViewController
,并在加载屏幕上停止。是。因此,从对象库中拖动另一个:您不应该更改类,应该更改唯一标识符。您可能希望在故事板中定义多个视图控制器。不,不是。实际上没有任何等价物。。。在StackExchange评论中没有一个简单的方法来解释它。Ray Wenderlich应该有很好的故事板教程。我会处理好的。谢谢你的及时回复!但是如何添加多个视图控制器?一旦我将Class
框从ViewController
更改为CameraVC3
,我的应用程序将不再加载Vie