2016-11-13 106 views
0

我的選項卡欄控制器出現問題!模擬我的項目時,我的選項卡欄控制器出現,第一個選項卡被選中,並顯示我已經放入第一個選項卡的視圖(所以這是完全正確的)。但是當我點擊第二個選項卡時,它將我帶回到xcode並在AppDelegate類的頂部顯示「Thread 1:signal SIGABRT」。我不知道爲什麼會發生這種情況,除了可能沒有正確鏈接。 有人可以通過步驟將視圖控制器鏈接到選項卡欄控制器的第二個選項卡嗎?謝謝!單擊第二個選項卡時選項卡欄不起作用

我在第二場景的故事板中有兩個標籤,一個開關,一個滑塊和一個按鈕。因爲我只需要擔心交換機和標籤的價值,這些是我使用插座連接到我的代碼的唯一兩件事情。

回答

0

1.標籤欄控制器與一個視圖控制器

enter image description here

2.添加第二個視圖控制器,帶的UILabel

enter image description here

3,按Ctrl +拖累標籤欄控制器到第二個視圖控制器

enter image description here

4.選擇從Relationship Segue - >view controllers

enter image description here

5.你的標籤欄控制器有兩個視圖控制器

enter image description here

6.結果

enter image description here

7.要訪問的標籤等,創建用於所述第二視圖控制器一個文件,在這個例子SecondViewController.swift從UIViewController中

import UIKit 

class SecondViewController: UIViewController { 

} 
繼承

8.在選擇了第二個視圖控制器的情節提要中,在中設置並回車

enter image description here

9.您的UI元素連接到文件和訪問它,CTRL +拖動例如從的UILabel到該文件,並給它一個名字,在這種情況下randomTextLabel

enter image description here

10。更改SecondViewController.swift的標籤與改變的UILabelviewDidLoad

import UIKit 

class SecondViewController: UIViewController { 

    @IBOutlet weak var randomTextLabel: UILabel! 

    override func viewDidLoad() { 
    super.viewDidLoad() 
    randomTextLabel.text = "Changed Label Text" 
    } 
} 

11.結果

enter image description here

+0

由於工作就像一個魅力。不知道什麼阻止了第一個視圖控制器的工作,但我剛剛刪除它,並按照這些說明,現在它工作。謝謝! – skyleguy

+0

是的,很高興我能幫助你! – ronatory

相關問題