As mentioned in the answer of the linked question, the TOCObj property of TableOfContents reporter was added in R2018b and hence you are unable to use it in R2018a.
To customize the number of levels in R2018a, you can customize the default template of the TableOfContents reporter to set the number of levels and then use this custom template to create your TableOfContents reporter. You can use mlreportgen.report.TableOfContents.createTemplate to create a copy of the default template and then customize it according to your requirements. As an example, to update the number of levels in PDF template, you will have to update the <toc> field in the dptemplate named TableOfContents as follows:
If you do not wish to customize the template and wants to achieve this programmatically, another alternative is to first get the DOM implementation of the TableOfContents reporter and then get access to the TOC from its children to customize it. Below is an example for a PDF report:
rpt = mlreportgen.report.Report("myReport","pdf");
reporter = mlreportgen.report.TableOfContents;
impl = getImpl(reporter,rpt);
tocObj = impl.Children(3);
tocObj.NumberOfLevels = 1;
Both the ways I have shown above demonstrates the TableOfContents customization for PDF reports. It may differ a little if you are generating a HTML or a DOCX report.
Hope this helps!