2015-12-04 25 views
-3

我有一個視圖,我從xib文件創建,添加UITableView時沒有問題。然後我試着給xib文件添加一個按鈕。該按鈕沒有出現在我的屏幕上。我已經使用IBOutlet將按鈕連接到頭文件。如何將按鈕添加到xib文件?

@property(strong,nonatomic)IBOutlet UIButton * deleteNotificationButton;

和我在M檔代碼

[self.view addSubview:_tblMain]; 
[self.view addSubview:_deleteNotificationButton 

這是我的故事板截圖 enter image description here

調試層次 enter image description here

表出現,但不是按鈕,我怎麼能讓按鈕出現?

+1

你不能把一個'UIButton'從廈門國際銀行文件的'UITableView'的子視圖。如果您需要放置一個按鈕,桌面視圖有自己的子視圖(頁眉,頁腳和單元格),您必須將其添加爲其中一個子視圖的子視圖。 – KIDdAe

+0

self.view不適用視圖 –

+0

爲什麼在實現文件中將視圖添加爲子視圖?通過將它們放在你的xib中,它們已經在視圖層次結構中。 – Stonz2

回答

0

這是關於層次結構的問題。您無需編寫任何代碼,只需在Storyboard或xib文件中執行此操作。

這是關於視圖的層次結構,您應該使用UIView作爲不是UITableView的根視圖。 enter image description here enter image description here

然後運行該項目,以及。順便說一下,如果將UIView設置爲rootView,則self.view =您設置的UIView,如果您將UITableView設置爲rootView,則self.view = UITableView。 enter image description here

您可以使用此按鈕調試,項目運行時,該按鈕就會顯示出來,然後檢查是否在視圖中的按鈕。 enter image description here

+0

我編輯我的答案,您可以嘗試此調試視圖。 – Lucifron

+0

我沒有找到我的按鈕,我甚至沒有找到我的表太 –

0
#Just use this line I have added below your two lines.Hope this works. 


[self.view addSubview:_tblMain]; 
[self.view addSubview:_deleteNotificationButton 
[self.view bringSubviewToFront:_deleteNotificationButton]; 
+0

我試過你的解決方案,但按鈕仍然沒有出現 –

+0

'addSubview:'總是在頂部添加視圖,那裏的第三行代碼是無關。 – vikingosegundo