2016-10-20 97 views
0

我正在使用以下代碼來使用集合加載我的表。點擊按鈕取消視圖

self.window = UIWindow(frame: CGRect(x:40, y:120, width:self.view.bounds.width-100, height:self.view.bounds.height-200)) 
self.window!.backgroundColor = UIColor.whiteColor() 

let mainController : CollectionViewController = CollectionViewController(nibName: "CollectionViewController", bundle: nil) 
myController.TableHeaderArray = TableHeaders 
let ApiResponse = self.dataTableViewdictParams(apiUrl) 
myController.UMIDDataArray = ApiResponse[0] as! NSMutableArray 
myController.TableDataArray = ApiResponse[1] as! NSMutableArray 
self.window!.rootViewController = myController 
self.window!.makeKeyAndVisible() 

我想刪除此表上的按鈕點擊並加載另一個視圖。在按鈕上單擊另一個視圖被加載,但我無法刪除此表UIWindowView。我該如何刪除它?

編輯:

我試過

添加代碼:

function loadanotherView() 
{ 
/// I tried these three codes but none worked for me 
self.window?.removeFromSuperview() // code 1 
self.window?.rootViewController?.removeFromParentViewController() // code 1 
self.window?.hidden = true // code 2 

let frame = CGRect(x:0, y:-20, width:self.view.bounds.width, height:self.view.bounds.width) 
WView.frame=frame 
let url = NSURL(string:"urlForTheWebView") 
let req = NSURLRequest(URL:url!) 
self.webView!.loadRequest(req) 
self.view.addSubview(WView) 

} 
+0

用你的刪除按鈕點擊方法更新你的問題 –

+0

添加按鈕點擊方法 – dang

+1

'tableView.dismissViewController()' –

回答

0

不要使用

self.window!.rootViewController = myController 

使用此

self.window?.addSubview(myController.view) 

而是採用

self.window?.removeFromSuperview() // code 1 
self.window?.rootViewController?.removeFromParentViewController() // code 1 
self.window?.hidden = true // code 2 

利用這一點,

myController.view.removeFromSuperview() // If Button on the another viewcontroller 

self.view.removeFromSuperview() // If Button on the myController 

因爲如果你做的myController的根,它不能從上海華刪除。因此,添加這個子視圖。

+0

當我使用self.window?.addSubview(myController.view)時,它給我錯誤。 – dang

+0

它說 - UICollectionView收到一個索引路徑不存在的單元格的佈局屬性: dang

+0

1st告訴我什麼是myController和mainViewController? – Pritam