Make sure index is validated.

fix this issue. <https://github.com/HeshamMegid/HMSegmentedControl/issues/42>