Close the current view and switch tab programmatically

Hello, I am using tab for my app and trying to close the current view, and then switch to other tab programmatically. However, it seems I cannot perform these two actions together no matter I go back before switch tab or after. Here is my code:


Thanks in advance.