2015-10-28 23 views
0

我在Swift App的viewController中添加了一個按鈕,當我通過modal segue更改爲下一個Viewcontroller時,此元素顯示在下一個viewController中。我怎樣才能刪除查看這個?如何刪除viewController中編碼的視圖按鈕?

override func viewDidLoad() 
{ 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    let logInButton = TWTRLogInButton(logInCompletion: { 
     (session: TWTRSession!, error: NSError!) in 
     ... 

     print(session.userName) 
     ... 

    }) 

    logInButton.center = self.view.center 
    self.view.addSubview(logInButton)//Here add the button 
} 

I'trying

self.view.delete(logInButton) 

但是,這得到錯誤。

謝謝!

+0

您得到了什麼錯誤? – userx

回答

0

你是否試圖從superview中刪除按鈕?在這種情況下,您需要嘗試:

loginButton.removeFromSuperview() 
+0

這個工作,並在包含的viewController中刪除。但在下一個控制器,這再次出現然後segue模式..我不知道爲什麼,如何刪除所有視圖的這一點? – user3745888

+0

當您從一個UIViewController延伸到另一個UIViewController時,如果您繼續使用與您所創建的UIViewController相同的自定義子類,則將具有與新實例中的第一個視圖控制器相同的按鈕和UI元素。如果我理解正確,你會想讓segue轉到不同的視圖控制器。 – Mackarous

相關問題