1

i wanna add a collectionView on the top of all the views in a tableViewController, so i used the code below in viewDidAppear

tableView.window?.addSubview(selectedView) 
tableView.window?.bringSubview(toFront: selectedView)

strangely, i couldnt saw the view as i supposed, and as i

po tableView.window

in the terminal, the answer is 'nil'

but the most strange thing is that the same code worked in another tableViewController

BTW: I knew the best way is using UIViewController to replace UITableViewController, but i just wanna know how could tableView.window is nil in viewDidLoad or viewDidAppear when using a UITableViewController

LouisHors
  • 11
  • 5
  • https://stackoverflow.com/questions/10278204/uiviewcontroller-view-window-is-null-in-viewdidload-method this question told that window will be nil when view havnt been added to the superView when viewDidLoad called, but how could this happen on a tableViewController with tableView? – LouisHors Dec 04 '17 at 02:53
  • In my case warning was caused by animated reload of data source in viewWillAppear(animated:): dataSource.apply(snapshot, animatingDifferences: animated) – Over Ukraine Mar 16 '20 at 16:57

0 Answers0