UIKit.UIImage initWithContentsOfFile Xamarin.iOS - 不可靠地抛出异常

时间:2017-03-20 15:54:15

标签: ios xamarin xamarin.ios uiimage

请考虑以下错误消息:

Could not initialize an instance of the type 'UIKit.UIImage": the native 'initWithContentsOfFile:' method returned nil.

我正在尝试在Xamarin PCL项目上加载页面,并且每隔一段时间就会在iOS上抛出此异常。所有Android测试看起来都很不错。

现在当我说“每隔一段时间”,我的意思是,或许每20个一次。我看不到它的任何模式。它似乎只发生在iPhone 5S上,但由于该bug的不可重复的性质以及有限的物理设备进行测试,我不能保证这种情况。

我可以确认,这不是我根据this SO帖子在标签页上设置图标的情况,所以请不要将其标记为重复(除非你找到另一个问题)

欢迎所有建议

编辑 - 加载导致问题的页面的XAML

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:Trak="clr-namespace:Trak"
             x:Class="Trak.FinishTrak">

    <ContentPage.Padding>
    <OnPlatform x:TypeArguments="Thickness">
      <OnPlatform.iOS>0,20,0,0</OnPlatform.iOS>
      <OnPlatform.Android>0,0,0,0</OnPlatform.Android>
    </OnPlatform>
  </ContentPage.Padding>

    <ContentPage.BindingContext>
        <Trak:TrackingPageScaling />
    </ContentPage.BindingContext>


  <ContentPage.Content>
    <RelativeLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

      <ScrollView Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
             RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
             RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
             RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0}"
             RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0}">

        <StackLayout Padding="0" Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">

          <!-- EVENT/TRAK CONTROL BAR -->
          <StackLayout Orientation="Horizontal">
            <Label  x:Name ="titleLabel"  Text="Untitled trak"
                   FontSize="{Binding FontSmall}"
                   TextColor="#333333"
                   HorizontalOptions="StartAndExpand"
                   VerticalOptions="Center">
              <Label.Margin>
                <OnPlatform x:TypeArguments="Thickness"
                            iOS     ="10,10,5,0"
                            Android ="10,15,5,10" />
              </Label.Margin>
            </Label>

            <Image Source="{Trak:ImageResource Trak.Images.edit.png}"
                   x:Name="editTrakDetails"
                   HorizontalOptions="End"
                   VerticalOptions="Center"
                   HeightRequest="20">
              <Image.Margin>
                <OnPlatform x:TypeArguments="Thickness"
                          iOS     ="10,5,5,0"
                          Android ="10,15,15,10" />
              </Image.Margin>
            </Image>
          </StackLayout>


          <!-- MAP IMAGE -->
          <StackLayout x:Name="imageLayout" Orientation="Horizontal" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Margin="0,0,0,0">
            <Image Source="{Trak:ImageResource Trak.Images.map.png}" VerticalOptions="Center" HorizontalOptions="FillAndExpand" HeightRequest="180" Margin="0,0,0,0"/>
          </StackLayout>

          <!-- TOP STATS-->
          <StackLayout Orientation="Horizontal" VerticalOptions="Center" HorizontalOptions="FillAndExpand" Margin="10,10,10,10">
            <StackLayout Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand">
              <Label x:Name="milesLabel" FontSize="{Binding FontMed}" TextColor="#333333" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,0,0,0"/>
              <Label Text="MILES" FontSize="{Binding FontXXSmall}" TextColor="#999999" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,-10,0,0" />
            </StackLayout>

            <StackLayout Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand">
              <Label x:Name="avrgMPHLabel" FontSize="{Binding FontMed}" TextColor="#333333" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,0,0,0"/>
              <Label Text="AVG MPH" FontSize="{Binding FontXXSmall}" TextColor="#999999" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,-10,0,0"/>
            </StackLayout>

            <StackLayout Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand">
              <Label x:Name="minutesLabel" FontSize="{Binding FontMed}" TextColor="#333333" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,0,0,0"/>
              <Label Text="MINUTES" FontSize="{Binding FontXXSmall}" TextColor="#999999" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,-10,0,0"/>
            </StackLayout>
          </StackLayout>

          <!-- DIVIDER -->
          <BoxView Color="#DCDCDC" HeightRequest="1" Margin="0"
                    VerticalOptions="Center" HorizontalOptions="FillAndExpand"></BoxView>

          <!-- BOTTOM STATS -->
          <StackLayout Orientation="Horizontal" VerticalOptions="Center" HorizontalOptions="FillAndExpand" Margin="10,10,10,10">
            <StackLayout Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand">
              <Label x:Name="caloriesLabel" FontSize="{Binding FontMed}" TextColor="#333333" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,0,0,0"/>
              <Label Text="CALORIES" FontSize="{Binding FontXXSmall}" TextColor="#999999" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,-10,0,0" />
            </StackLayout>

            <StackLayout Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand">
              <Label x:Name ="elevationLabel" FontSize="{Binding FontMed}" TextColor="#333333" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,0,0,0"/>
              <Label Text="ELEVATION" FontSize="{Binding FontXXSmall}" TextColor="#999999" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,-10,0,0"/>
            </StackLayout>

            <StackLayout Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand">
              <Label x:Name ="HRLabel" FontSize="{Binding FontMed}" TextColor="#333333" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,0,0,0"/>
              <Label Text="AVERAGE HR" FontSize="{Binding FontXXSmall}" TextColor="#999999" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,-10,0,0"/>
            </StackLayout>
          </StackLayout>

          <!-- DIVIDER -->
          <BoxView Color="#DCDCDC" HeightRequest="1" Margin="0"
                  VerticalOptions="Center" HorizontalOptions="FillAndExpand"></BoxView>

          <StackLayout Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand" Margin="10,10,10,10">
            <Label Text="NOTES:" FontSize="{Binding FontSmall}"  TextColor="#333333" />
            <Label x:Name="trakNOTES" TextColor="#333333" FontSize="{Binding FontXSmall}">
              Use this space to add any notes about your Trak. It mabe used to add weather condidtions, nutrition, road surface etc. You can also use the icons below to quickly add weather conditions or road surfaces. More icons will be added in time.
            </Label>
          </StackLayout>

          <!-- WEATHER AND TERRAIN TOGGLE ICONS -->
          <StackLayout Orientation="Horizontal" VerticalOptions="Center" HorizontalOptions="FillAndExpand" Margin="10,10,10,20">
            <Image Source="{Trak:ImageResource Trak.Images.MeIcons.sun-grey.png}" x:Name="sunButton" WidthRequest="50" HeightRequest="50" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
            <Image Source="{Trak:ImageResource Trak.Images.MeIcons.rain-grey.png}" x:Name="rainButton" WidthRequest="50" HeightRequest="50" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
            <Image Source="{Trak:ImageResource Trak.Images.MeIcons.cloudy-grey.png}" x:Name="cloudButton" WidthRequest="50" HeightRequest="50" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
            <Image Source="{Trak:ImageResource Trak.Images.MeIcons.road-grey.png}" x:Name="roadButton" WidthRequest="50" HeightRequest="50" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
            <Image Source="{Trak:ImageResource Trak.Images.MeIcons.trail-grey.png}" x:Name="trailButton" WidthRequest="50" HeightRequest="50" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
          </StackLayout>

          <!-- SAVE TRAK BUTTON-->
          <Button Text="Save" x:Name="saveButton"
              Clicked="OnSaveButtonClick"
              BackgroundColor="#ffffff"
              FontSize="14" TextColor="#037ade"
              BorderWidth="2" BorderColor="#037ade"
              Grid.Row="11" Grid.Column="1"
              VerticalOptions="Center" HorizontalOptions="Center"
              WidthRequest="200" HeightRequest="50"
              Margin="0,5,0,25"/>

        </StackLayout>

      </ScrollView>


      <StackLayout x:Name="editTrakModalShadow" BackgroundColor="#000000" Opacity="0" IsVisible="false" Padding="5"
         HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
         RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
         RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
         RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0}"
         RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0}" />

      <!-- MODEL TO SAVE TRAK INFO -->
      <StackLayout x:Name="saveTrakModal" BackgroundColor="#FFFFFF" Opacity="0" IsVisible="false"
        RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.8}"
        RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.1}"
        RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.1}">

        <!-- TITLE INPUT -->
        <Label Text="TITLE:" TextColor="#333333" HorizontalTextAlignment="Start" HeightRequest="20" Margin="20,40,20,5"/>
        <Entry x:Name="trakTitle" Placeholder="Enter file name" HorizontalOptions="FillAndExpand" HeightRequest="50" Margin="20,5,20,5"/>

        <!-- DETAILS  INPUT -->
        <Label Text="NOTES:" TextColor="#333333" HorizontalTextAlignment="Start" HeightRequest="20" Margin="20,40,20,5"/>
        <Editor x:Name="trakNotes" HorizontalOptions="FillAndExpand" HeightRequest="100" Margin="20,5,20,5"/>

        <!-- SAVE TRAK -->
        <Button x:Name="saveTrakButton" Text="UPDATE" Clicked="saveTrakModelButton" BackgroundColor="#ffffff"
          FontSize="14" TextColor="#037ade"
          BorderWidth="2" BorderColor="#037ade" Margin="20,5,20,5"/>

        <!-- CANCEL -->
        <Button Text="CANCEL" Clicked="closeTrakModel" BackgroundColor="#ffffff"
          FontSize="14" TextColor="#ff6961"
          BorderWidth="2" BorderColor="#ff6961"
          Margin="20,5,20,30"/>

      </StackLayout>

    </RelativeLayout>

  </ContentPage.Content>

</ContentPage>

0 个答案:

没有答案