Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. [tab setSelectedIndex:2];
  2.  
  3. [[NSUserDefaults standardUserDefaults]setObject:yourArray forKey:@"YourKey"];
  4.  
  5. NSMutableArray *array=[[NSUserDefaults standardUserDefaults]objectForKey:@"YourKey"];
  6.  
  7. override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  8. if segue.identifier == "toTabController" {
  9. var tabBarC : UITabBarController = segue.destinationViewController as UITabBarController
  10. var desView: CaseViewController = tabBarC.viewControllers?.first as CaseViewController
  11.  
  12. var caseIndex = overviewTableView!.indexPathForSelectedRow()!.row
  13. var selectedCase = self.cases[caseIndex]
  14.  
  15. desView.caseitem = selectedCase
  16. }
  17. }
  18.  
  19. @IBAction func sendBtnListener(sender: AnyObject) {
  20. Singleton.sharedInstance.brandName = self.searchDisplayController!.searchBar.text
  21. self.tabBarController!.selectedIndex = 2
  22. }
  23.  
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26.  
  27. //Nothing is printed out for this portion of code except the first time
  28. if !Singleton.sharedInstance.brandName.isEmpty{
  29. println(Singleton.sharedInstance.brandName)
  30.  
  31. }else{
  32.  
  33. println("Empty")
  34. }
  35. }
  36.  
  37. class Singleton {
  38. var name : String = ""
  39. class var sharedInstance : Singleton {
  40. struct Static {
  41. static let instance : Singleton = Singleton()
  42. }
  43. return Static.instance
  44. }
  45.  
  46. var brandName : String {
  47. get{
  48. return self.name
  49. }
  50.  
  51. set {
  52. self.name = newValue
  53. }
  54. }
  55. }
  56.  
  57. class firstViewController: UIViewController ,UITabBarControllerDelegate{
  58. let arrayName = ["First", "Second", "Third"]
  59. override func viewDidLoad() {
  60. super.viewDidLoad()
  61.  
  62. self.tabBarController?.delegate = self
  63. }
  64.  
  65. func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
  66. if viewController .isKind(of: firstsubsecoundViewController.self as AnyClass ) {
  67. let viewController = tabBarController.viewControllers?[1] as! secondViewController
  68. viewController.arraydata = self.arrayName
  69. }
  70. return true
  71. }
  72. }
  73.  
  74. class secondViewController: UIViewController {
  75. var arraydata:[String] = NSArray()
  76. override func viewDidLoad() {
  77. super.viewDidLoad()
  78. print(arraydata)
  79. }
  80. }
  81. //OutPut:- ["First", "Second", "Third"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement