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


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">
                                <RowDefinition Height="27"/>
                                <ColumnDefinition Width="60"/>
                                <ColumnDefinition Width="5"/>
                                <ColumnDefinition Width="105"/>
                                <ColumnDefinition Width="35"/>
                                <ColumnDefinition Width="60"/>
                                <ColumnDefinition Width="36"/>
                            <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" />

View Model code

    public AutoWithSwitch SelectedItem
            return _selectedItem;
            _selectedItem = value;

            if (_selectedItem == null)

    public async void DisplayAlerts(AutoWithSwitch value)
        Application.Current.Properties["DeleteData"] = value;            

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)
    public void ShortAlert(string 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!


Source link

Leave a Reply

Your email address will not be published.