NAXAM / toptabbedpage-xamarin-forms

TopTabbedPage - A Xamarin.Forms page for showing tabs at top on iOS
Apache License 2.0
81 stars 24 forks source link

(iOS) Out of range exception when 0 children are present #21

Closed jochembroekhoff closed 5 years ago

jochembroekhoff commented 5 years ago

The renderer throws an exception when the TopTabbedPage is renderer without any children. This issue is specific to iOS. On Android it works just fine. I did a little bit of debugging myself, and I think that the issue is located at the following lines:

https://github.com/NAXAM/toptabbedpage-xamarin-forms/blob/master/Naxam.TopTabbedPage.Platform.iOS/TopTabbedRenderer.cs#L138-L143

As you can see there, the if statement checks if lastSelectedIndex >= 0 || lastSelectedIndex < ViewControllers.Count, but that will also pass if the selected index is 0 and when ViewControllers.Count is 0. The || here should be replaced with &&.