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

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

Related

Xamarin Forms WebView open external link

I have a webview inside my application and when an external link is clicked (that in normal browser is open in a new tab), I can't then go back to my website.
It is possible when a new tab is open to have the menu closed that tab like Gmail do ?
The objective is that, whenever a link is clicked, the user would have the choice to choose which option to view the content with, e.g. Clicking a link would suggest open youtube app or google chrome. The purpose is to appear the google chrome option
Or what suggestions do you have to handle this situation ?
If I understood you correctly, you want to have the option to select how to open the web link - inside your app, or within another app's (browser) context.
If this is correct, then you can use Xamarin.Essentials: Browser functionality.
public async Task OpenBrowser(Uri uri)
{
await Browser.OpenAsync(uri, BrowserLaunchMode.SystemPreferred);
}
Here the important property is the BrowserLaunchMode flag, which you can learn more about here
Basically, you have 2 options - External & SystemPreferred.
The first one is clear, I think - it will open the link in an external browser.
The second options takes advantage of Android's Chrome Custom Tabs & for iOS - SFSafariViewController
P.S. You can also customise the PreferredToolbarColor, TitleMode, etc.
Edit: Based from your feedback in the comments, you want to control how to open href links from your website.
If I understood correctly, you want the first time that you open your site, to not have the nav bar at the top, and after that to have it. Unfortunately, this is not possible.
You can have the opposite behaviour achieved - the first time that you open a website, to have the nav bar and if the user clicks on any link, to open it externally (inside a browser). You have 2 options for this:
To do it from your website - change the a tag's target to be _blank like this;
To do it from your mobile app - create a Custom renderer for the WebView. In the Android project's renderer implementation, change the Control's WebViewClient like so:
public class CustomWebViewClient : WebViewClient
{
public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request)
{
Intent intent = new Intent(Intent.ActionView, request.Url);
CrossCurrentActivity.Current.StartActivity(intent);
return true;
}
}

Navigation From One View Controller to Another

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)

Mac os x main window controller

When I create a cocoa based mac osx application in xcode. I get a default class AppDelegate which is sublcass of NSObject < NSApplicationDelegate >
The application is one main window which has some buttons , tableview etc,
My question is should I make this AppDelegate class to be the controller of my main window ? or should I create a new controller. Under what condition should I choose my delegate to be the controller and when should I not ?
If the application is not some throwaway test application you should create a new controller and put there logic for the view. If the application starts to grow you may need even more controllers and views e.g. Status bar could be separate view with a separate controller.
In the AppDelegate you should put only the things that are specific for the complete application like menu, starting, stopping etc.

Adding a back button to table view with embedded Navigation Controller Xcode

Here is the flow of my app so far.
View controller (HOME) with rect button (modal) linking to > Table view controller with an embedded navigation controller linked to> Multiple View controllers with an image on each.
This work perfectly s but......
I want to have a "back" button on my Table view controller to take me back to my (HOME) View controller.
I am new to this and have tried to find relevant info and tried loads of options but noting seems to work and although i can see a button in the simulator (and have Modal linked it to my (HOME) view ) the simulator crashes every time and this error message appears.....
*2013-01-05 17:19:40.080 MASTER DETAIL POLAR TEST[10975:f803] -[HomeController setCharacterNumber:]: unrecognized selector sent to instance 0x6894620
2013-01-05 17:19:40.084 MASTER DETAIL POLAR TEST[10975:f803] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HomeController setCharacterNumber:]: unrecognized selector sent to instance 0x6894620'**
Please Help.....
may it would be the best your HOME viewController is embedded in the navigationController an become RootViewController. By clicking the rect-button the tableViewController will appear.
Use the navigationControllers method – pushViewController:animated: or create a new segue an select "push".
If you don't like this way you have to add a navigationBarButtonItem to the navigationBar. Link this button item to an action which send the message dismissViewControllerAnimated:completion: to the tableViewController. This should work.

SIGBART NSInternalInconsistencyException attempting transition while transition in progress

I'm extending Appirater (a stand alone class that presents an UIAlertView to the user to solicit a rating for your app) by adding a single button that when selected will dismiss the alert, and bring up MFMailComposerViewController so the user can email feedback.
My implementation was/is to post a notification in Appirater, and then using [self presentModalViewController: vc animated: YES] from a viewController that listens for the notification. That viewController is the super class of all my main viewControllers.
It works in one of the main viewControllers is up, but crash's from within other viewControllers are the current viewController and I see the following warning in the console:
2010-12-17 11:27:59.632
Wine.com[18514:207] * Terminating
app due to uncaught exception
'NSInternalInconsistencyException',
reason: 'Attempting to begin a modal
transition from to
while a transition is
already in progress. Wait for
viewDidAppear/viewDidDisappear to know
the current transition has completed'
I tried delaying the sending of the notification from Appirater, but that does not seem to help.
Ideas/pointers?
I had a similar error when clicking on a UIButton to open a Modal View. I changed the UIButton's listener from UIControlEventAllEvents to UIControlEventTouchUpInside. Basically, it was firing the Modal View on Touch Down Inside and then trying to create another instance of the Modal View on Touch Up Inside.
The problem was that by implementing this in a superclass, I needed to make sure only the currently active viewController was processing the notification, not ALL 5 of them.

Resources