Fix bugs about didSelectRowAtIndexPath

My code should be more defensive.