I want to create a slidebar menu in my app (As shown in the image below)
When I click that hamburger icon, it should show a menu as shown below.
I am currently using the SWRevealController, a lib written in Objective C. I created a bridging header and imported the class. This is my current Set up
My initial view which branches to a Menu Controller or the UIViewTable is a SWRevealController, and the segues are subclasses of SWRevealViewControllerSegueSetController. In my Food Item View Controller (the controller where the hamburger navigation exist), I added the following code to activate the slidebar action.
override func viewDidLoad() {
super.viewDidLoad()
//Creating the slidebar Navigation using SWRevealViewController
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
However, when I click the button, it is still not responding. When I did this with my other application, it worked fine. I am not sure why it is not working here
This is the source I used as reference: http://www.appcoda.com/sidebar-menu-swift/
View Controller Full Code
#IBOutlet weak var thumbnail_image: UIImageView!
//#IBOutlet weak var food_detail: UITextView!
#IBOutlet weak var testing: UILabel!
#IBOutlet weak var menuButton: UIBarButtonItem!
var jsonResponseFood: NSArray = NSArray() //API for types of food available
var jsonResponseRecipe: NSArray = NSArray() // API for recipes in food
var selectedFood: foodItem?
var postStr: String?
//Initializing API
let FullRecipeAPIModel = fullRecipeAPIModel()
override func viewDidLoad() {
super.viewDidLoad()
//Creating the slidebar Navigation using SWRevealViewController
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
print(selectedFood?.name as String!)
//testing.text = self.selectedFood?.name
let APIModel = apiModel()
APIModel.delegate = self
FullRecipeAPIModel.delegate = self
APIModel.downloadItems(postString: postStr!)
// Do any additional setup after loading the view.
}
Thank you StackOverflow.
Problem in your code is you are not setting SWRevealController as root view.No Storyboard option available by code wise we have to do configuration once again. This library was designed like that. so if you change code as below it will work like a charm.
if(stat == "login"){
if(responseString == "invalid"){
self.isValid = false;
print(self.isValid)
}
DispatchQueue.main.async(execute: {
if self.checkLogin(data: responseString!) == true {
let storyboard = UIStoryboard(name: "food", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "foodItemViewController") as! foodItemViewController
let navController = UINavigationController(rootViewController: controller) // Creating a navigation controller with VC1 at the root of the navigation stack.
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let menuView :MenuController = storyboard.instantiateViewController(withIdentifier: "menuBar") as! MenuController
let revealController = SWRevealViewController()
revealController.frontViewController = navController;
revealController.rearViewController = menuView;
appDelegate.window?.rootViewController = revealController
}
else{
//Show alert here
self.showAlert(title: "User Does Not Exist", alertTitle: "Close", message: "");
}
});
}
else{
//CODE COULD BE SIMPLIFIED
DispatchQueue.main.async(execute: {
if(responseString == "duplicate"){
//Show alert here
self.showAlert(title: "User with this email already exist", alertTitle: "Close", message: "Please register with another email address")
}
else{
//Show Food UITable
let storyboard = UIStoryboard(name: "food", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "entranceFoodController")
/*let navController = UINavigationController(rootViewController: controller) // Creating a navigation controller with VC1 at the root of the navigation stack.*/
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let menuView :MenuController = storyboard.instantiateViewController(withIdentifier: "menuBar") as! MenuController
let revealController = SWRevealViewController()
revealController.frontViewController = controller;
revealController.rearViewController = menuView;
appDelegate.window?.rootViewController = revealController }
});
}
I am also working on this today, is that the best choice available to use SWRevealController, isn't there an Apple built in way of doing this?. I am eager to see options instead of getting something form Github, unless that is my last resort.
Related
Goal: In a separate storyboard that is loaded via a storyboard reference in the main.storyboard, in a pageViewController acting as the initial view controller, I want to initialize an array object of viewControllers via the function .instantiateViewController(identifier:).
Issue: The last viewController I'm trying to instantiate as a constant is not loading. The error - *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load the scene view controller for identifier 'FinalVC''"
All other viewControllers in this storyboard load fine. This last view controller has a correct custom class linked and a unique storyboard identifier.
Debugging: I've created a breakpoint where this view controller is instantiated and noticed in the debugging console all other view controller objects load as "BillyCues.repeatViewController + unique identification number" while this last vc loads as "UIViewController + 0x000000000000000". It's almost as if this vc is not a part of the app bundle or referenced correctly but it's there when I search in the directory.
Debugging console screen
Things I've tried that did not work:
Check to see if another vc has the same identifier
Clean the build folder
Check "Use Storyboard ID" in the identity inspector
let finalVC = storyBoard.instantiateViewController(identifier: "FinalVC") as! FinalViewController
Restart Xcode
Create a brand new view controller with a different storyboard identifier using the same custom class
Removed all connections from buttons and labels in the last vc
Made sure all storyboard references in main.storyboard has the correct storyboard linked
Conclusion: All my googling has led to other developers encountering the error about NIBs or tableviews not necessarily a view controller. If my vc has a correct custom class and unique identifier the error should not occur. If anyone can offer guidance I'd appreciate it; I'm dumbfounded.
I hope I've asked for help in an appropriate structure but please let me know if more code or screenshots are needed.
PageViewController Code
import UIKit
class LauncherViewController: UIPageViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.setViewControllers([viewControllerList[0]], direction: .forward, animated: false, completion: nil)
// Do any additional setup after loading the view.
}
private var viewControllerList: [UIViewController] = {
let storyBoard = UIStoryboard.cueCreation
let firstVC = storyBoard.instantiateViewController(identifier: "CueNameVC")
let secondVC = storyBoard.instantiateViewController(identifier: "DueDateVC")
let thirdVC = storyBoard.instantiateViewController(identifier: "IconVC")
let fourthVC = storyBoard.instantiateViewController(identifier: "IconColorVC")
let fifthVC = storyBoard.instantiateViewController(identifier: "RepeatVC")
let finalVC = storyBoard.instantiateViewController(identifier: "FinalVC") as! FinalViewController
return [firstVC, secondVC, thirdVC, fourthVC, fifthVC, finalVC]
}()
var selectedReminderBill: CueObject?
public var currentIndex = 0
static var cueName: String = ""
static var cueDate: Date = Date()
static var cueIcon: Data = Data()
static var iconColor:String = "14CC7F"
static var repeatMonthly: Bool = false
// Navigation button functions below to move to the next or previous page
func pushNext() {
if currentIndex + 1 < viewControllerList.count {
self.setViewControllers([self.viewControllerList[self.currentIndex + 1]], direction: .forward, animated: true, completion: nil)
currentIndex += 1
}
}
func pullBack() {
print(currentIndex)
if currentIndex - 1 < viewControllerList.count {
self.setViewControllers([self.viewControllerList[self.currentIndex-1]], direction: .reverse, animated: true, completion: nil)
currentIndex -= 1
}
}
}
FinalViewController Code
import UIKit
import UserNotifications
import RealmSwift
class FinalViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
cueName.text = LauncherViewController.cueName
dueDate.text = CueLogic.convertPaymentDateToString(for: LauncherViewController.cueDate)
iconBackgroundView.backgroundColor = colorLogic.colorWithHexString(hexString: LauncherViewController.iconColor)
cueIcon.image = UIImage(data: LauncherViewController.cueIcon)
repeatsMonthly.text = repeatMonthlyToString
}
override func viewDidLoad() {
super.viewDidLoad()
cueName.layer.cornerRadius = 15
cueName.clipsToBounds = true
iconBackgroundView.layer.cornerRadius = 20
iconBackgroundView.clipsToBounds = true
dueDate.layer.cornerRadius = 15
dueDate.clipsToBounds = true
repeatsMonthly.layer.cornerRadius = 15
repeatsMonthly.clipsToBounds = true
backButton.layer.cornerRadius = 15
backButton.clipsToBounds = true
saveButton.layer.cornerRadius = 15
saveButton.clipsToBounds = true
// Do any additional setup after loading the view.
}
let colorLogic = ColorLogic()
let realm = try! Realm()
weak var delegate: HomeScreenDelegate?
var launcher = LauncherViewController()
var repeatMonthlyToString: String {
get {
if LauncherViewController.repeatMonthly == true {
return "Repeats Monthly: Yes"
} else {
return "Repeats Monthly: No"
}
}
}
#IBOutlet var cueName: UILabel!
#IBOutlet var dueDate: UILabel!
#IBOutlet var saveButton: UIButton!
#IBOutlet var backButton: UIButton!
#IBOutlet var iconBackgroundView: UIView!
#IBOutlet var cueIcon: UIImageView!
#IBOutlet var repeatsMonthly: UILabel!
#IBAction func dismissButtonTapped(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
#IBAction func backButtonTapped(_ sender: Any) {
if let pageController = parent as? LauncherViewController {
pageController.pullBack()
}
}
#IBAction func saveButtonTapped(_ sender: Any) {
// Request authorization from the user to allow notifications
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound], completionHandler: {success, error in
if success {
// schedule test
} else if let error = error {
print("error occured \(error)")
}
})
let newCue = CueObject()
let launcherVC = LauncherViewController.self
newCue.name = launcherVC.cueName
newCue.paymentDate = launcherVC.cueDate
newCue.icon = launcherVC.cueIcon
newCue.iconColor = launcherVC.iconColor
newCue.repeatsMonthly = launcherVC.repeatMonthly
NotificationLogic.scheduleLocalAlertForBill(named: newCue.name, due: newCue.paymentDate, repeatsMonthly: newCue.repeatsMonthly)
saveToDB(for: newCue)
delegate?.loadCuesFromRealm()
self.dismiss(animated: true, completion: nil)
}
func saveToDB(for cue: CueObject) {
do {
try realm.write({
realm.add(cue)
})
} catch {
print("Error - \(error)")
}
}
}
protocol HomeScreenDelegate: AnyObject {
func loadCuesFromRealm()
}
Extension I wrote in another viewController
extension UIStoryboard {
static let onboarding = UIStoryboard(name: "Onboarding", bundle: nil)
static let main = UIStoryboard(name: "Main", bundle: nil)
static let cueCreation = UIStoryboard(name:"CueCreation", bundle: nil)
}
Identity Inspector
Main Storyboard References
I'd do a few things as part of cleanup to start debugging the actual issue. In the storyboard extension, I'd rather use a static function to reference the view controller.
extension UIStoryboard {
class func createFinalVC() -> FinalViewController? {
return UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FinalVC") as? FinalViewController)
}
}
And for implementing it, I'd use in the view controller presenting FinalViewController:
private func createCreateFinalVC() -> FinalViewController? {
return UIStoryboard.createFinalVC()
}
And finally pushing it into the view,
if let finalVC = createCreateFinalVC() {
yourNavController?.pushViewController(finalVC, animated: true)
}
Solution
I began a process of elimination and started to comment out all of the code in my FinalVC class. I learned that this line of code var launcher = LauncherViewController() was triggering the crash.
Given my limited beginner knowledge I don't know why this would cause a crash; I can only assume that Xcode was trying to initialize two LauncherViewControllers with identical identifier numbers or something along those lines.
Hey my code changes data in another view controller on 2nd attempt on 1st just showing default values
Code inside button
#IBAction func check(_ sender: Any) {
makeRequest()
let fin = UIStoryboard(name: "FinalViewController", bundle: nil)
let pop = fin.instantiateInitialViewController()! as! FinalViewController
pop.img = icon
pop.state = state
pop.fail = failed
self.present(pop, animated: true)
}
Code inside 2nd view controller
class FinalViewController: UIViewController {
#IBOutlet weak var weathure_icon: UIImageView!
#IBOutlet weak var status: UILabel!
var fail = false
var img = ""
var state = ""
override func viewDidLoad() {
if fail == false{
super.viewDidLoad()
status.text = state
weathure_icon.image = UIImage(named: img+".png")
}
}
Please check three things in your code inside the button action.
Please cross-check, is makeRequest() asynchronous request??
is icon, state and failed parameters request coming from makeRequest() method, in this case you need to handle request data on main thread.
Please replace following in your code:
This
let fin = UIStoryboard(name: "FinalViewController", bundle: nil)
let pop = fin.instantiateInitialViewController()! as! FinalViewController
With
let fin = UIStoryboard(name: "STORYBOARD_NAME", bundle: nil)
let pop = fin.instantiateInitialViewController(identifier: "FinalViewController")! as! FinalViewController
Hope this will help you and make success with your implementation :)
I have a sign up viewController(VC). Once the user submits his registration details, my remote server responds with a 'registration_success'. Upon receiving this message, I am able to present a new VC that requests that the user check their email to verify their email address. I am able to present the new view controller but failing to transfer the user's email address to the new VC. My code is below:
guard
let registeredEmail = myArray["email"] as? String else{
print("cannot find email address")
return
}
let verifyEmailVC = self.storyboard?.instantiateViewController(withIdentifier: "emailConfirmVC") as! VerifyEmailViewController
print("registeredEmail: \(registeredEmail)")
verifyEmailVC.emailToVerify.text! = registeredEmail
self.present(verifyEmailVC, animated: true, completion: nil)
class VerifyEmailViewController:
class VerifyEmailViewController: UIViewController {
#IBOutlet var emailToVerify: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
}
console:
jsonObject: {
email = "tran123#gmail.com";
firstname = Wang;
lastname = tran;
message = "registration_success";
status = 200;
userId = 53;
}
message: registration_success
registeredEmail: tran123#gmail.com
I am getting the following error:
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an
Optional value
in line: verifyEmailVC.emailToVerify.text! = registeredEmail
Label in the VerifyViewController is nil and you are trying to set value to that lable. Try passing string to your controller like this
let verifyEmailVC = self.storyboard?.instantiateViewController(withIdentifier: "emailConfirmVC") as! VerifyEmailViewController
print("registeredEmail: \(registeredEmail)")
verifyEmailVC.email = registeredEmail
self.present(verifyEmailVC, animated: true, completion: nil)
class VerifyEmailViewController: UIViewController {
#IBOutlet var emailToVerify: UILabel!
var email: String?
override func viewDidLoad() {
super.viewDidLoad()
emailToVerify.text = email
}
I have modified your code with few correction try below code
let verifyEmailVC = self.storyboard?.instantiateViewController(withIdentifier: "emailConfirmVC") as! VerifyEmailViewController
print("registeredEmail: \(registeredEmail)")
verifyEmailVC.emailToVerifyStr = registeredEmail
self.present(verifyEmailVC, animated: true, completion: nil)
In VerifyEmailViewController
class VerifyEmailViewController: UIViewController {
var emailToVerifyStr = ""
#IBOutlet var emailToVerify: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated:Bool){
super.viewWillAppear(true)
self.emailToVerify.text = emailToVerifyStr
}
}
Hope that will help you :)
First of all, having JSON object used by your high level objects like ViewController is not something I would recommend.
You should consider having a "Store" object which receives the JSON, create a User object.
Then, you can create your one init function to pass your User object directly.
Like this :
- (instancetype)initWithUser(User *)user {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
self = [storyboard instantiateViewControllerWithIdentifier:#"emailConfirmVC"];
if(self) {
//default initialization
}
return self;
}
I created the structure as below in xcode 8 swift 3.0.
Before I add AppDelegate code. Back button still appear fine on Apply, Apply Behalf and Profile controller.
I use segue to open page.
But after I add AppDelegate code into Homepage and Login controllers , back button disappears on Apply, Apply behalf and profile controller page.
Can someone help or explain why is this happening ? How to enable back the back button on apply, apply behalf and profile page ?
Thanks.
Home.swift
import UIKit
class ViewController: UIViewController {
#IBOutlet var staffNumberLbl: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
staffNumberLbl.text = UserDefaults.standard.object(forKey: "login") as? String
}
override func viewDidAppear(_ animated: Bool) {
let isUserLoggedIn = UserDefaults.standard.bool(forKey: "loggedIn")
if(!isUserLoggedIn){
self.performSegue(withIdentifier: "loginview", sender: self)
}
}
#IBAction func logoutData(_ sender: Any) {
UserDefaults.standard.set(false, forKey: "loggedIn")
UserDefaults.standard.synchronize();
let loginViewController = self.storyboard!.instantiateViewController(withIdentifier: "loginview") as! LoginViewController
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = loginViewController
appDelegate.window?.makeKeyAndVisible()
}
}
Login.swift
import UIKit
class LoginViewController: UIViewController {
#IBOutlet var loginlbl: UITextField!
#IBOutlet var passlbl: UITextField!
#IBOutlet var login_button: UIButton!
var login: String!
var pw: String!
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func loginData(_ sender: Any) {
login = loginLbl.text
pw = passLbl.text
if(login == "" || pw == ""){
return
}
else{
let url = URL(string: "http://localhost/login.php")
let session = URLSession.shared
let request = NSMutableURLRequest(url: url! as URL)
request.httpMethod = "POST"
let LoginDataToPost = "login=\(login!)&pw=\(pw!)"
request.httpBody = LoginDataToPost.data(using: String.Encoding.utf8)
let task = session.dataTask(with: request as URLRequest, completionHandler: {
(data, response, error) in
if error != nil {
return
}
else {
do {
if let json = try JSONSerialization.jsonObject(with: data!) as? [String: String]
{
DispatchQueue.main.async
{
let message = Int(json["message"]!)
let login = json["login"]
if(message == 1) {
UserDefaults.standard.set(true, forKey: "isUserLoggedIn")
UserDefaults.standard.set(login, forKey: "login")
UserDefaults.standard.synchronize();
self.dismiss(animated: true, completion: nil)
let myViewController:ViewController = self.storyboard!.instantiateViewController(withIdentifier: "ViewController") as! ViewController
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = myViewController
appDelegate.window?.makeKeyAndVisible()
print("Value for login is : \(login!)")
return
}
else {}
}
}
else {}
}
catch let jsonParse {}
}
})
task.resume()
}
}
}
AppDelegate.swift
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let isUserLoggedIn:Bool = UserDefaults.standard.bool(forKey: "isUserLoggedIn")
if(!isUserLoggedIn) {
let loginViewController = mainStoryBoard.instantiateViewController(withIdentifier: "loginview") as! LoginViewController
window!.rootViewController = loginViewController
window!.makeKeyAndVisible()
}
else {
let homePage = mainStoryBoard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
window!.rootViewController = homePage
window!.makeKeyAndVisible()
}
return true
}
}
You are setting rootviewcontroller without embedding navigation controller to it in logoutData & loginData function.
Use this code :
let navigationController = UINavigationController.init(rootViewController: myViewController)
appDelegate.window?.rootViewController = navigationController
Use this code in AppDelegate:
if(!isUserLoggedIn) {
let loginViewController = mainStoryBoard.instantiateViewController(withIdentifier: "loginview") as! LoginViewController
let navigationController = UINavigationController.init(rootViewController: loginViewController)
appDelegate.window?.rootViewController = navigationController
window!.makeKeyAndVisible()
}
else {
let homePage = mainStoryBoard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
let navigationController = UINavigationController.init(rootViewController: homePage)
appDelegate.window?.rootViewController = navigationController
window!.makeKeyAndVisible()
}
Remove this from Home.swift,
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = loginViewController
appDelegate.window?.makeKeyAndVisible()
because its not inheriting the properties of Navigation controller
and add it in Appdelegate.swift file
For the other 3 viewcontrollers, you need to add the Navigation controller between eachSegway in order to inherit it or code the button by instantiating the viewcontrollers respectively
After successful login,try to make NavigationController as rootViewController instead of your ViewController
Your back button will start appearing.
In AppDelegate, in else block, instead of this line
let homePage = mainStoryBoard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
write this
let homePage = mainStoryBoard.instantiateViewController(withIdentifier: "NavigationController") as! UINavigationController
Inside LoginViewController, in the block if(message == 1)
replace
let myViewController:ViewController = self.storyboard!.instantiateViewController(withIdentifier: "ViewController") as! ViewController
with
let navController:UINavigationController = self.storyboard!.instantiateViewController(withIdentifier: "NavigationController") as! UINavigationController
Also set storyboard identifier for UINavigationController in storyboard to NavigationController
Depending on your configuration:
self.navigationItem.hidesBackButton = YES;
OR:
self.navigationController.navigationItem.hidesBackButton = YES;
Or, if you just want to disable the button without hiding it, you can use this.
self.navigationController.navigationItem.backBarButtonItem.enabled = NO;
I recently started to learn swift and it has been pretty good so far. Currently I'm having an issue trying to pass data between view controllers. I managed to figure out how to programmatically navigate between two view controllers using a navigation controller. Only problem is now I'm having a hard time trying to figure out how to pass three string entered by the user (for json api) to the next view.
Here's my current attempt. Any help is much appreciated!
ViewController:
/* Get the status code of the connection attempt */
func connection(connection:NSURLConnection, didReceiveResponse response: NSURLResponse){
let status = (response as! NSHTTPURLResponse).statusCode
//println("status code is \(status)")
if(status == 200){
var next = self.storyboard?.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
self.presentViewController(next, animated: false, completion: nil)
}
else{
RKDropdownAlert.title("Error", message:"Please enter valid credentials.", backgroundColor:UIColor.redColor(), textColor:UIColor.whiteColor(), time:3)
drawErrorBorder(usernameField);
usernameField.text = "";
drawErrorBorder(passwordField);
passwordField.text = "";
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
let navigationController = segue.destinationViewController as! UINavigationController
let newProjectVC = navigationController.topViewController as! SecondViewController
newProjectVC.ip = ipAddressField.text
newProjectVC.username = usernameField.text
newProjectVC.password = passwordField.text
}
SecondViewController:
import UIKit
class SecondViewController: UIViewController {
var ip:NSString!
var username:NSString!
var password:NSString!
override func viewDidLoad() {
super.viewDidLoad()
println("\(ip):\(username):\(password)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
The method prepareForSegue is called when your app's storyboard performs a segue (a connection that you create in storyboards with Interface Builder). In the code above though you are presenting the controller yourself with presentViewController. In this case, prepareForSegue is not fired. You can do your setup right before presenting the controller:
let next = self.storyboard?.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
next.ip = ipAddressField.text
next.username = usernameField.text
next.password = passwordField.text
self.presentViewController(next, animated: false, completion: nil)
You can read more about segue here
Updated syntax for Swift 3:
let next = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as? SecondViewController
next.ip = ipAddressField.text
next.username = usernameField.text
next.password = passwordField.text
self.present(next, animated: true, completion: nil)