Reputation: 2965
view object is not getting in addsubview bracket
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool
{
// Override point for customization after application launch.
UIApplication.sharedApplication().setStatusBarHidden(true, animated: true);
var myView = UIView(frame:CGRectMake(0, 200, 320, 100));
myView.backgroundColor = UIColor.redColor()
self.window.?.addSubview(myView)
return true
}
Upvotes: 0
Views: 12149
Reputation: 1096
In addition to your code, for UIApplication Root view controller's viewDidAppear Function add below code.
override func viewDidAppear(animated: Bool)
{
super.viewDidAppear(animated)
UIApplication.sharedApplication().delegate!.window!!.bringSubviewToFront((UIApplication.sharedApplication().delegate!.window!!.subviews[0]))
}
Hope that helps :)
Upvotes: 2
Reputation: 1592
Try to use so if access through UIViewController
let win:UIWindow = UIApplication.sharedApplication().delegate!.window!!
win.addSubview(self)
Upvotes: 9
Reputation: 24041
please, do the implementation for the stack properly, like e.g. this:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let mainViewController: MainViewController = MainViewController(nibName: "MainViewController", bundle: nil)
window!.rootViewController = mainViewController
window!.makeKeyAndVisible()
return true
}
Upvotes: 4