c# – Cannot get Alerts to show on iPhone no matter what way I code it and I have tried 4 different ways

[ad_1]

Of these 4 methods mentioned, they all work in the simulator, but non of them work on the iPhone. Here are the pieces of code that come into play here.

<ListView x:Name="AutoView" ItemsSource="{Binding AutoData}" SelectedItem="{Binding SelectedItem}" SeparatorVisibility="None"  Grid.Row="1" Grid.ColumnSpan="6" BackgroundColor="Purple">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="27"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="60"/>
                                <ColumnDefinition Width="5"/>
                                <ColumnDefinition Width="105"/>
                                <ColumnDefinition Width="35"/>
                                <ColumnDefinition Width="60"/>
                                <ColumnDefinition Width="36"/>
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Grid.Row="0" FontSize="Medium" TextColor="White" Text="{Binding Year}" HorizontalTextAlignment="Center"/>
                            <Label Grid.Column="2" Grid.Row="0" FontSize="Medium" TextColor="White" Text="{Binding Name}" Grid.ColumnSpan="2"  HorizontalTextAlignment="Start"/>
                            <Switch x:Name="{Binding Id}" IsToggled="{Binding IsChecked, Mode=TwoWay}" Toggled="Handle_Toggled" Grid.Column="6" Grid.Row="0" />
                        </Grid>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

View Model code

    public AutoWithSwitch SelectedItem
    {
        get
        {
            return _selectedItem;
        }
        set
        {
            _selectedItem = value;

            if (_selectedItem == null)
                return;
            DisplayAlerts(value);
        }
    }

    public async void DisplayAlerts(AutoWithSwitch value)
    {           
        Application.Current.Properties["DeleteData"] = value;            
        DependencyService.Get<IMessage>().LongAlert("Stupid");            
    }

Interface defined in the common project

public interface IMessage
{
    void ShowMsg(Mileage value);
    void LongAlert(string message);
    void ShortAlert(string message);
}

Code in iOS project to display the alert

    public void LongAlert(string message)
    {
        ShowAlert(message);
    }
    public void ShortAlert(string message)
    {
        ShowAlert(message);
    }

    void ShowAlert(string message)
    {
        UpdateCarsViewModel ucvm = new UpdateCarsViewModel();
        //alertDelay = NSTimer.CreateScheduledTimer(seconds, (obj) =>
        //{
        //    dismissMessage();
        //});
        alert = UIAlertController.Create(null, "Action", UIAlertControllerStyle.Alert);
        alert.AddAction(UIAlertAction.Create("Delete", UIAlertActionStyle.Default,UIAlertAction => ucvm.DeleteCar()));
        alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
        UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null);
    }

Again, this works in the simulator but on the iPhone it does absolutely nothing. Any help you could give me would be much appreciated. Thanks so much!

[ad_2]

Source link

Leave a Reply

Your email address will not be published.