Closed wpcfan closed 5 years ago
@wpcfan can you include your SideBarViewController.xml file?
@nicklockwood , the xml is as follows, just a very simple tableview
<Example.SideBarViewController>
<UITableView
backgroundColor="clear"
contentInset.bottom="safeAreaInsets.bottom"
contentInset.top="parent.top"
contentInsetAdjustmentBehavior="never"
contentOffset.y="0"
estimatedSectionHeaderHeight="0"
outlet="tableView"
scrollIndicatorInsets.bottom="safeAreaInsets.bottom"
scrollIndicatorInsets.top="parent.top"
style="plain"
top="parent.top">
<!-- Table cell template -->
<UITableViewCell
detailTextLabel.highlightedTextColor="#fff7"
detailTextLabel.text="This cell is defined as a template in Table.xml"
detailTextLabel.textColor="#aaa"
height="auto + 20"
reuseIdentifier="sidebarCell"
selectedBackgroundView.backgroundColor="tintColor"
style="subtitle"
textLabel.highlightedTextColor="white"
textLabel.text="Title #{row}">
</UITableViewCell>
</UITableView>
</Example.SideBarViewController>
So I figure it out, If I change Example.SideBarViewController to UIViewController, all problems gone. But I don't understand, so when to use UIViewController instead of a specific controller name?
@wpcfan it should work if you just remove the outer view controller from your XML and leave the tableView.
You cannot load a class from inside itself, so what was happening is that the SideBarViewController was loading a new instance of SideBarViewController from the xml and then trying to add it as a child to itself.
When you changed it to a regular UIViewController, it started adding that UIVC as a child controller instead, which fixes the crash, but you probably just want to add the TableView directly as a child view of ExampleViewController instead, without an intermediate view controller.
@nicklockwood thanks for detailed clarification, very helpful. closing this issue
I have a similar setup with the Sample App, i.e. I have a tabviewcontroller and 3 tabs: Home, Social and Me. In the MeViewController, I want to launch a drawer-like viewcontroller (which is also layout-based) when clicking the left nav button, but I ran into an exception, so I would like to know what is the recommended way to do this
The Layout xml is
The MeViewController is as follows
The SidebarViewController is as follows