passing data from one tab controller to another in swift
you can use this code : Objective C
[tab setSelectedIndex:2];
save your array in NSUserDefaults
like this:
[[NSUserDefaults standardUserDefaults]setObject:yourArray forKey:@"YourKey"];
and get data from another view using NSUserDefaults
like this :
NSMutableArray *array=[[NSUserDefaults standardUserDefaults]objectForKey:@"YourKey"];
swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "toTabController" {
var tabBarC : UITabBarController = segue.destinationViewController as UITabBarController
var desView: CaseViewController = tabBarC.viewControllers?.first as CaseViewController
var caseIndex = overviewTableView!.indexPathForSelectedRow()!.row
var selectedCase = self.cases[caseIndex]
desView.caseitem = selectedCase
}
}
How to pass data between different tabs in a tab bar controller
Have a look at this question: iPhone: How to Pass Data Between Several Viewcontrollers in a Tabbar App
Also the imho cleanest way is to use the NSNotificationcenter. It's simple: How to use NSNotificationcenter
Segue from modal view to tab bar view controller and not lose tab bar
Here is my example of how to do this. In my setup, I choose the yellow ViewController from the tab, then press Go! which modally presents the white ViewController. Pressing Exit returns to the green ViewController.
To set this up, use an unwind segue to return to the viewController that called you. For instance, implement this in the first ViewController of the tab (the one calling the modal segue).
@IBAction func backFromModal(_ segue: UIStoryboardSegue) {
print("and we are back")
// Switch to the second tab (tabs are numbered 0, 1, 2)
self.tabBarController?.selectedIndex = 1
}
Then switch to another tab using self.tabBarController?.selectedIndex = n
where n
is the number of the tab you really want to go to. To set up the unwind segue, you can either control-drag from a button in your modal view controller to the exit icon at the top of the viewController and select backFromModal
from the pop up...
OR
you can set up the unwind segue to be called programmatically by control-dragging from the viewController icon at the top of the modal viewController to the exit icon, and select backFromModal
from the pop up.
Then, go to the Document Outline View and click on the unwind segue
and give it an identifier in the Attributes Inspector on the right (for example "returnFromModal"
).
Then you'd call the unwind segue like this:
self.performSegue(withIdentifier: "returnFromModal", sender: self)
Related Topics
How to Parse Array of JSON to Array in Swift
Pinch to Zoom Effect on Uiimageview Inside Scrollview
How to Start an Ibeacon Transmitter in the Background
Restore Button for iOS Non-Consumable In-App Purchase
Dismiss a Parent Modal in Swiftui from a Navigationview
Building Ffmpeg iOS Libraries for Armv7, Armv7S, Arm64, I386 and Universal
How to Make a Mkannotationview Touch Sensitive
How to Permanently Allow Usage of Camera on Trusted Websites with iOS - Safari
Running Nsurlsession Completion Handler on Main Thread
How to Programmatically Get iOS's Alphanumeric Version String
How to Find the Kind of Errors a Method May Throw and Catch Them in Swift
How to Prevent a Remote Notification from Being Displayed
Error: Uitableview Jump to Top with Uitableviewautomaticdimension