Getting black screen except navigation Bar SWIFT - uiviewcontroller

My all previous projects works fine with this simulator but now whenever i'm creating new ViewController in previous projects or in new project, then ViewController looks black except Nav Bar. I don't know what's the problem even i reset my simulator but nothing solve my problem,
i think this problem seem to be so complicated.
import UIKit
class ViewController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Currently View Controller looks here
ScreenShot attached here 1 and 2
I will be very glad if any of them help me.
Thanks

This is a UINavigationController, not a UIViewController So you need to embed UIViewController with this UINavigationController.
That's why you are getting the black screen.
You need to embed UIViewController with this navigation controller.

It's because you are using UINavigationController as superclass of your ViewController. You can change superclass to UIViewController and embed your ViewController in UINavigationController.
Updated code:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Image that shows how you can embed your ViewController:

Related

Linking an SKScene to a UIViewController

When you create a new game file in swift, by default you are given a GameScene.swift file, a GameViewController.swift file, and a UIViewController on your main.storyboard. In my code I have created another SKScene (similar to the GameScene already present), and I am having trouble linking it to another UIViewController that I have on my main.storyboard. I want to do this because i need to segue from my GameScene to this new scene and then to my Main ViewController / Initial Viewcontroller
How do I link the SKScene and ViewController correctly?
Below is the EndSceneViewController.swift file, and then the EndScene.swift file i want to link it to.
import UIKit
import SpriteKit
class EndSceneVC: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
if let scene = EndScene(fileNamed:"EndScene") {
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
scene.viewController = self
skView.presentScene(scene)
}
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return .AllButUpsideDown
} else {
return .All
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override func prefersStatusBarHidden() -> Bool {
return true
}
}
import SpriteKit
class EndScene : SKScene {
var viewController : UIViewController?
override func didMoveToView(view: SKView) {
print("hello")
}
}
You want to move from scene to scene by switching controllers?
Root ViewController can be targeted from the currently displayed SKScene - you don't have to add another property to your scene.
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
let viewController = self.view?.window?.rootViewController
}
}

Xamarin iOS - Refresh View coming back from another view

I have a View 1 (UIViewController) which has a button to navigate to a new view - View 2 (UIViewController).
I would like to refresh View 1 when user clicks back button from View 2. UIViewController does not have ViewWillAppear to know the control is back on the view.
How to determine the control is passed on that view
You can override ViewDidAppear to detect that View 1 is visible again and refresh the view. Do not forget to call the base method too.
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear (animated);
//Refresh view here.
}
UIViewController does not have ViewWillAppear
You don't have the method ViewWillAppear on an UIViewController?
You could try to use the UINavigationControllerDelegate and specifically WillShowViewController
1)We can set it with a bool Value.
bool viewLoadedAgain = false;
2)Bool value gets 'true' when segue triggers:
public override void PrepareForSegue (UIStoryboardSegue segue, Foundation.NSObject sender)
{
base.PrepareForSegue (segue, sender);
if(segue.Identifier == "segueToSecondVC")
{
viewLoadedAgain = true;
}
}
3) Perform Refreshing ViewController View.
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
this.PerformSegue ("segueToSecondVC",this);
if(viewLoadedAgain == true)
{
//Use any code as per requirement
this.View.SetNeedsLayout ();
this.View.SetNeedsUpdateConstraints ();
this.View.ReloadInputViews ();
this.View.SetNeedsDisplay ();
}
}

Using Swift, how to create a UIViewController over another one using StoryBoards

I have a viewcontroller that hold a button for now, and I want to create a new viewcontroller and add his view over the current one
So far I did this:
class ViewController : UIViewController
{
var myController: MyController = MyController.controller()
init(coder aDecoder: NSCoder!)
{
super.init(coder: aDecoder)
}
init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!)
{
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
override func viewDidLoad()
{
super.viewDidLoad()
self.view.addSubview(self.myController.view)
}
#IBAction func buttonPressed(sender : AnyObject)
{
}
}
in MyController I did a singleton (I hope I did it right)
class MyController : UIViewController
{
init(coder aDecoder: NSCoder!)
{
super.init(coder: aDecoder)
}
init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!)
{
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
class func controller() -> MyController
{
var once : dispatch_once_t = 0
var sharedInstance: MyController?
dispatch_once(&once, { sharedInstance = MyController()})
return sharedInstance!
}
}
the behavior I got is this, if I DON'T call the
self.view.addSubview(self.myController.view)
everything works fine, if I did, the button in the center is not anymore recognizing the touches, it is like it has something over that intercept the touch, what is wrong here? what I'm missing?
in MyController I did a singleton (I hope I did it right)
You did it wrong. Singleton is not required here. If you are using storyboard, the below line
var myController: MyController = MyController.controller()
could be
var myController: MyController = self.storyboard.instantiateViewControllerWithIdentifier("MyViewController")
Then before adding sub view set the frame of the self.myController.view
self.myController.view.frame = CGRectMake(0, 0, 320, 200); // or what ever frame you want

Export a subclassed UIViewController with btouch

I am trying to export Cordova into Monotouch. For the most part it is working, but the issue that I am encountering is that the delegate methods for CDVViewController (which is derived from UIViewController) do not fire. Neither the delegate methods defined in CDVViewController nor the events that I define Monotouch (ie a class derived from CDVViewController) seem to fire.
Here is some code; first snippets of the Cordova code that I am trying to export:
CDVViewController.h:
#interface CDVViewController : UIViewController<UIWebViewDelegate, CDVCommandDelegate> {
}
#property (nonatomic, strong) CDVCordovaView* webView;
CDVViewController.m:
#implementation CDVViewController
#synthesize webView;
- (void) viewDidLoad
{
[super viewDidLoad];
NSLog(#"%s","Cordova viewDidLoad");
}
My btouch definition is as follows:
using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace Omnimove.Web.Cordova
{
[BaseType(typeof(UIWebView))]
interface CDVCordovaView
{
}
[BaseType (typeof (UIViewController))]
interface CDVViewController
{
[Export ("webView")]
CDVCordovaView WebView { get; set; }
}
}
And here is my class that derives from CDVViewController in Monotouch:
public class UIFormsViewController : CDVViewController
{
public override void ViewDidLoad ()
{
Console.WriteLine (#"UIFormsViewController ViewDidLoad()");
base.ViewDidLoad ();
}
}
As I mentioned at the start, the code does compile and the UIFormsViewController does display its containing CDVCordovaView (UIWebView), but the ViewDidLoad defined in UIFormsViewController and the viewDidLoad defined in CDVViewController do not seem to fire at all. Can anyone explain why this is and how I would go about correcting this?
If there's a viewDidLoad implemented in CDVViewController (and there IS one), make sure you expose it in your bindings, so the C# will have it as well and will think about calling it, instead of skipping to its parent.
Something like this should do it:
ApiDefinition.cs
using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace Omnimove.Web.Cordova
{
[BaseType(typeof(UIWebView))]
interface CDVCordovaView
{
}
[BaseType (typeof (UIViewController))]
interface CDVViewController
{
[Export ("webView")]
CDVCordovaView WebView { get; set; }
[Export ("viewDidLoad")]
void ViewDidLoad ();
}
}

How to refresh my UIVIewController using SetNeedsDisplay

I have a simple UIViewController (in monotouch), with a button on the UI. Now, my use case is simple - I want to reload the UIViewController whenever the button is clicked. On some threads i read that i just need to call SetNeedsDisplay for the UIView, but that doesn't seem to work for me. Here is my code snippet -
public partial class AbcScreen : UIViewController
{
....
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Declare and Add a button
Add(myBtn);
myBtn.TouchUpInside += (sender, ea) =>
{
Console.WriteLine("Touched the button");
View.SetNeedsDisplay();
};
}
}
I read some other threads, but nothing seems to help. Please help! Thanks!
Try with
this.ReloadInputViews();