Iphone remove sub view
The clue is here
for (UIView *subView in self.view.subviews)
each subView is of class UIView and your test
isKindOfClass:[TableViewController class]
is testing for class TableViewController
I would suggest a way of doing this would be by tagging the views that you add dynamically, with say 99 - and then in your loop you can identify those views by their tag.
eg.
for (UIView *subView in self.view.subviews){ if (subView.tag == 99) { [subView removeFromSuperview]; }}
Swift version
To remove a single subview:
subView.removeFromSuperview()
To remove all subviews:
for subView in self.subviews as [UIView] { subView.removeFromSuperview()}
Source: What is the best way to remove all views from parent view / super view?
Try this,
if ([subView isKindOfClass:[UITableView class]]) { [subView removeFromSuperview];}