简而言之,我正在呈现一个刚刚添加到视图层次结构中的childVC视图,但显然它尚未添加到窗口层次结构中。
我刚刚开始这个项目并将其设置为基于页面的项目。添加到包含的class Foo():
def __init__(self):
self.x = 1
self.y = 2
self.z = 3
f = Foo()
f2 = Foo()
f2.x = 10
print(convert_tuple([f,f2]))
[(1, 2, 3), (10, 2, 3)]
的{{1}}的锅炉是:
text=data.getText().toString();
PrintWriter writer=null;
try {
FileOutputStream os = openFileOutput(filename, Context.MODE_PRIVATE);
writer=new PrintWriter(os);
} catch (Exception e) {
// log exception
}
writer.print(text);
writer.flush();
writer.close();
msg.setText("Data Saved Successfully");
我改变的唯一一行是将我自己的VC设置为UIPageViewController
:
RootViewController
我正在尝试让第一个屏幕成为相机 - 一个ImagePickerVC。这是我的代码。正如您所看到的,我正在向此override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// Configure the page view controller and add it as a child view controller.
self.pageViewController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
self.pageViewController!.delegate = self
let startingViewController: CameraViewController = self.modelController.viewControllerAtIndex(0, storyboard: self.storyboard!)!
let viewControllers = [startingViewController]
self.pageViewController!.setViewControllers(viewControllers, direction: .Forward, animated: false, completion: {done in })
self.pageViewController!.dataSource = self.modelController
self.addChildViewController(self.pageViewController!)
self.view.addSubview(self.pageViewController!.view) // !! -- viewDidAppear for CameraViewController called here
// Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
var pageViewRect = self.view.bounds
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0)
}
self.pageViewController!.view.frame = pageViewRect
self.pageViewController!.didMoveToParentViewController(self)
// Add the page view controller's gesture recognizers to the book view controller's view so that the gestures are started more easily.
self.view.gestureRecognizers = self.pageViewController!.gestureRecognizers
}
添加startingViewController
以显示预览,但我尝试首先在 let startingViewController: CameraViewController = self.modelController.viewControllerAtIndex(0, storyboard: self.storyboard!)!
上展示UIImageView
:
CamerViewController
但是,我收到警告,UIImagePickerController
永远不会出现:
viewDidAppear
我已设置断点,发现在import UIKit
class CameraViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
@IBOutlet var imageView: UIImageView!
@IBAction func didTapCameraButton(sender: AnyObject) {
presentImagePicker();
}
var dataObject: AnyObject?
var imagePicker: UIImagePickerController!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated);
presentImagePicker();
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func presentImagePicker() {
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .Camera
presentViewController(imagePicker, animated: false, completion: { () -> Void in
println("save bolean")
})
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
imagePicker.dismissViewControllerAnimated(true, completion: nil)
imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
}
}
添加imagePicker
时,此行上会调用Warning: Attempt to present <UIImagePickerController: 0x14e833a00> on <Here.CameraViewController: 0x14e614af0> whose view is not in the window hierarchy!
viewDidAppear
:
CameraViewController
这似乎应该是错误的原因?视图刚刚添加,因此它位于RootViewController的视图层次结构中。
我还添加了一个按钮,可以从PageViewController
手动显示RootViewController
。这表明没有任何问题。