Search code examples
iosobjective-cios11addsubviewuivisualeffectview

iOS 11 - Crash on adding subview inside VKSideMenu


I have been using the VKSideMenu library for implementing slide menu. I have a created a button click for animating the same. The code was working perfectly before iOS 11 but since when I updated my iPhone to iOS11 the app gets crashed whenever I clicked on the button. Adding an exception breakpoint helped me to find out where the cause is but I could not found the reason for that cause anywhere .

In the VKSideMenu.m file, I got the issue at

[self.view addSubview:self.tableView];

where the self.tableView indicates the tableview for displaying the menu. But the tableview was not nil.


Solution

  • After hours of sitting, I finally got the solution. Replace this line

    [self.view addSubview:self.tableView];
    

    with

    [[(UIVisualEffectView *)self.view contentView] addSubview:self.tableView];
    

    If you want to add a subview ( for e.g., a subview named subViewName) to that view, you have to add this:

    [[(UIVisualEffectView *)self.view contentView] addSubview:subViewName];