viewcontroller

Adding & Removing A View Overlay in Swift

ぃ、小莉子 提交于 2019-11-30 13:33:14
问题 Following from this question: Loading Screen from any Class in Swift Issue : The loading overlay view will display but will not hide when hideOverlayView() is called. Oddly however, the overlay disappears after some time (15 to 30 seconds after it appears) Code : Contained in FirstController.swift public class LoadingOverlay{ var overlayView = UIView() var activityIndicator = UIActivityIndicatorView() class var shared: LoadingOverlay { struct Static { static let instance: LoadingOverlay =

How to reference the current Viewcontroller from a Sprite Kit Scene

故事扮演 提交于 2019-11-30 09:08:35
I'm having a hard time finding the answer to this question I assume is not that hard. How can I reference methods and properties defined on a viewcontroller from a SKScene ? And building on that: How can you reference the ViewController from a SKScene that was loaded from within another SKScene? A better option than my "back reference" answer is to use a protocol to explicitly define the methods that a SKScene subclass expects the UIViewController subclass to implement. Here are the steps you'll need to go through. 1) Define the protocol (contract) that the UIViewController will need to adopt

iOS: Is there currently a way to prevent two view controllers being pushed or popped at the same time?

烈酒焚心 提交于 2019-11-30 09:07:29
问题 The only solution I have seen was an answer to a stackoverflow question. I posted the link below. The answer I am referring is the 5th one. It seems that some users have some problems with the solution however. I don't know if there is another category to prevent two controllers from being pushed at the same time. Any tips or suggestions are appreciated. #import "UINavigationController+Consistent.h" #import <objc/runtime.h> /// This char is used to add storage for the isPushingViewController

What is better place for loading data from API- viewDidLoad, viewWillAppear or viewDidAppear?

为君一笑 提交于 2019-11-30 07:10:49
问题 I am making an IOS app where i am calling an API in viewDidLoad method of view controller. Now i want to reload the same view controller with the data that comes from server. How many ways are there to do this task and what would be the best way?? Please help me. Thanks!! 回答1: viewDidLoad method is called first time when UIViewController is first loaded and when it pop and then you reenter in it at that time viewDidLoad is called. So if you want to load the API only once then viewDidLoad is

Passing data received from a push notification from the AppDelegate to a ViewController

混江龙づ霸主 提交于 2019-11-30 03:42:36
问题 In my app, there's a collection view displaying a set of images retrieved from a web service. Each image has tags. So the app has the ability to filter images using tags as well. Now I'm trying to add push notifications to this app. A push notification is sent when new images have been added to the server. These images are tagged say, latest . I'm passing that tag as the message via a push notification and what I need is when the user taps on the push notification to open the app, it should

Loading ViewController from xib file

旧街凉风 提交于 2019-11-30 02:58:37
I had a MyViewController.swift and a MyViewController.xib presenting the layout of MyViewController. I tried different methods to load this view controller including: //1 let myVC = UINib(nibName: "MyViewController", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as? MyViewController //2 let myVC = NSBundle.mainBundle().loadNibNamed("MyViewController", owner: self, options: nil)[0] as? MyViewController //3 let myVC = MyViewController(nibName: "MyViewController", bundle: nil) The third one is the only successful initialisation, but the previous two are causing error: Terminating app

Swift performSegueWithIdentifier shows black screen

自闭症网瘾萝莉.ら 提交于 2019-11-29 18:04:43
I have read through a lot of different posts regarding this issue, but none of the solutions seemed to work for me. I started a new app and I placed the initial ViewController inside a navigation controller. I created a second view and linked them together on the storyboard with a segue. The segue works successfully, and I can see the data I am transferring in a print statement from the second screen, but the screen shows black. WelcomeScreen: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "segueToTraits"{ if let gender = self

Adding a view to the window hierarchy

故事扮演 提交于 2019-11-29 14:55:17
问题 I am trying to create a pause screen on my game. I have added a 'PauseScreen' viewController in my storyboard with the Storyboard ID and Restoration ID set as "PauseScreenID" and to move to the pause screen I have have created the function in "GameScene" : func pauseSceenTransition(){ let viewController = UIStoryboard(name: "Main", bundle:nil).instantiateViewControllerWithIdentifier("PauseScreenID") as UIViewController let currentViewController = (UIApplication.sharedApplication().delegate as

Return to root view in IOS

有些话、适合烂在心里 提交于 2019-11-29 14:31:57
To some this may sound like a daft question. I've searched around, and found little, mostly because I cannot find the appropriate search terms. Here what I want to do is: The application begins at view A. View A launches view B, and view B launches view C. Is their a way for view C to return directly back to A without dismissing itself and thus exposing B. For example a main menu button. You can call popToRootViewControllerAnimated: if you have a UINavigationController. If you specify NO to animate it, then it will just jump back to the root without showing B first. I have discovered a

Inter-ViewController parameters passing in iPhone programming… how to?

只谈情不闲聊 提交于 2019-11-29 12:53:40
I read: iPhone: How to Pass Data Between Several Viewcontrollers in a Tabbar App and was wondering what is the difference between [[UIApplication sharedApplicaton] delegate] and extern struct* global ? Conceptually, I don't see how [[UIApplication sharedApplicaton] delegate] not being a global thing. In fact, that lessen the sense of guilty when using the dirty global struct * now. I am starting a new project very soon. So, I use this break to ask the question: is there any best-practice code example to illustrate how to share data between two ViewControllers (but not globally)? Let me put it