Navigation From One View Controller to Another - xcode

I am a .Net Developer and just started my first iOS project using swift. I want to navigate from one view controller to another using code. Like we do in WP 8.1 with the help of following code:
Frame.Navigate(Typeof("Page_2"));

Another way that you can do it depending on how you are calling or executing the code.
self.performSegueWithIdentifier("YourSegueIdentifier", sender: self)

Give your destination view controller an identifier (in storyboard). Then, put this into the view controller you're navigating from...
let controller = self.sender.storyboard?.instantiateViewControllerWithIdentifier("resultController") as! ResultController
controller.myViewModel= myViewModel!
self.sender.navigationController?.pushViewController(controller, animated: true)

Related

How can I implement SfMap in Xamarin

How can I implement SfMaps in my project which is based on MVVM structure? 1st I have to get my current location and show it on the map then I have to drag that marker point anywhere and set it as the current location
Add SfMaps to your project from NuGet. In android no need for native configurations, but to launch the SfMaps in iOS, call the SfMapsRenderer.Init() in the FinishedLaunching overridden method of the AppDelegate class
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
…
global::Xamarin.Forms.Forms.Init ();
Syncfusion.SfMaps.XForms.iOS.SfMapsRenderer.Init();
LoadApplication (new App ());
…
}
Add the following namespace in your view file.
xmlns:maps="clr-namespace:Syncfusion.SfMaps.XForms;assembly=Syncfusion.SfMaps.XForms"
And add the below code to initializing map in view
<maps:SfMaps >
</maps:SfMaps>
this is a very basic way to add SFMap in Xamarin. forms for more details and help
please visit this link: https://help.syncfusion.com/xamarin/maps/getting-started?cs-save-lang=1&cs-lang=xaml

keyDown(with:) Not Called on Custom ViewController or View, Only WindowController

I have moved most of the core functionality of my non-document based macOS app to a custom, embedded framework.
The app code has a standard main storyboard with an initial window, and the window has a "window content" relationship/segue into a storyboard reference pointing to a storyboard inside the embedded framework. Therein lies a custom NSViewController subclass and a custom NSView subclass.
I want to group all the input event handling code inside the framework, which means implementing mouseDown(with:) on the custom NSView subclass, and --lo and behold-- it gets called when I click inside the app window. So far, so good.
Next, I implemented keyDown(with:) to similarly handle keyboard input. However, at runtime, it does not get called and instead, I hear the annoying beep (NSBeep).
I tried implementing keyDown(with:) on the view controller instead, but it's all the same.
Finally, I tried implementing the key handler on my NSWindowController subclass instead, and that does work.
So I could get around this by forwarding the event like so:
class WindowController: NSWindowController {
override func keyDown(with event: NSEvent) {
contentViewController?.view.keyDown(with: event)
}
}
, but it is very inelegant. I would prefer to not pollute the app code with input logic.
This doesn't seem to have anything to do with embedding frameworks, however. I put together a minimal project from the 'Cocoa App' template and confirmed that indeed keyDown(with:) only gets called if implemented on the window controller code, but not on the view or view controller side.
How can I get keyDown(with:) to be called on the view or view controller (not the window or window controller) in a storyboard-based app? (so I can move it from the main app to my embedded framework).
Edit: The question has been marked as duplicate. I tried the solutions pointed in answers to the other question (namely, override acceptsFirstResponder to return true). This solves the problem in my minimal demo project, but when I tried it on my full app, it still does not work (I did see that question and did try to override acceptsFirstResponder in my app before posting this question).
I will now try to modify my minimal poeject to see if I can reporduce the issue in the main app.
Edit 2: I have refactored the minimal project to:
Send the view controller to a separate storyboard,
Send the view controller's storyboard and represented classes (custom view, custom view controller) to a separate, embedded framework.
Now the basic setup mirrors that of my app in all that seems to matter, but still can not reproduce the issue in the minimal project. I will investiate further...
Edit 3: I haven't been able to reproduce the issue on the minimal project.
On my app's custom view, I implemented:
public override var acceptsFirstResponder: Bool {
return true
}
public override func performKeyEquivalent(with event: NSEvent) -> Bool {
let retVal = super.performKeyEquivalent(with: event)
return retVal
}
On startup, acceptsFirstResponder is called twice.
When hitting any key, performKeyEquivalent(with:) is called twice, too. Inspectig the intermediate variable retVal above reveals that the super class's implementation always returns false. After returning from this method, NSBeep() is called and keyDown(with:) isn't.
If instead of super.performKeyEquivalent(with:) I force-return true, I can avert the call to NSBeep() (but keyDown(with:) is still not called...)
Edit 4 (Final):
Out of desperation, I cleared the "Custom Class" field of the window controller's Identity Inspector in my app's main storyboard (to the default NSWindowController).
Suddenly, my custom view's keyDown(with:) starts getting called.
I reinstated the custom class to confirm.
It still works.
I clean the build folder and try again.
It still works.
Now I can no longer reproduce the issue even on my main app. I really don't know what to say...

xcode swift: how to display a website as pop-over

I am working on an app with links to external websites. I have been using code that opens safari separately, but I would like code that opens the website as a pop-over. Is this an option?
UIApplication.sharedApplication().openURL(NSURL(string:"http://www.bing.com")!)
You can use a UIWebView and load the url into it, you can add that to an existing view or create a view controller with a web view in it and present it as a popover.
let aWebView = UIWebView()
let myUrl = NSURL(string: "http://www.google.com")
let urlRequest = NSURLRequest(URL: myUrl!)
aWebView.loadRequest(urlRequest)
self.view.addSubview(aWebView)

How do I connect my Navigation Controller to every screen of my storyboard?

I am using Swift and Xcode 6.1.1, I used a navigation controller in my story board and set it as the initial view. I have a sign up screen and a login screen and I use buttons to navigate with segues between them. After the user logs in I segue to the main app view but how would I do this using my navigation controller.
In my app delegate didFinishLoadingWithOptions is create a var navController = UINavigationController() but how do I let this variable connect with the navigation controller in my Storyboard. I want to be able to set new views as the root view once an action has succeeded like a successful login.
I am still learning alot about iOS development please explain like I am a 5 year old.
you don't have to manual create a UINavigationController in "app delegate".
as you said,you have edit "initial view controller" setting in "Interface builder" already! so when the app startup,the "initial view controller"(also UINavigationController,as you set) is created automatic!
All you have to do is create a relationship bettween the first UINavigationController(login view) with another UIViewController(login sucess view).
How to do this?
Just hold "control" key and from "UINavigationController" drag a blue line to the "login sucess UIViewController",and select "init root viewcontroller" in "releationship segue" section at the popmenu!
you can read this article for more detail
enter storyboards-tutorial-in-ios-7-part-1

User interface is not visible when the app runs (only in interface builder)

I'm stuck on a very stupid issue. I've built my mac osx app user interface with Interface Builder (and xcode3).
Now when I run my app I can't see the app window (but only the menu on top).
The MyDocument.xib file is correctly loaded (from xCode navigation sidebar) and I can see my user interface in interface builder.
In my code I haven't changed this method:
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return #"MyDocument";
}
What am I doing wrong ?
thanks
Check out the following methods in the NSApplicationDelegate documentation:
(BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
(BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
Each window has an option (checkbox) called visible at start (or something like that; can't check ATM). Doublecheck if that's activated.
It was a bad configured ArrayController!
No error messages.. just the interface not showing up

Resources