Why can not I see my carousel in ios and in android if I can?

OscarNavarroCoriaOscarNavarroCoria USMember ✭✭
edited July 2018 in Xamarin.Forms

I'm doing a project in Xamarin forms, I'm using the nuget CarouselView.XamarinPlugin package, and when I run the application, the carousel if it looks in android, but it does not look in ios, what could be happening?

this is my code in XamarinForms
private View[] _views;

        public frmDetalle(int idUsuario)
        {
            InitializeComponent();
            try
            {
                this.idUsuario = idUsuario;
                lblSaludo.Text = utileriasServices.getSaludo();
                lblFecha.Text = utileriasServices.getFecha();

                Device.BeginInvokeOnMainThread(async () =>
                {
                    var response = await fortiaServices.PostAsinc<AccountModel>(new Account { IdUser = this.idUsuario }, "/GetInfoInit");
                    if (response != null)
                    {
                        this.accountModel = response;

                        Device.BeginInvokeOnMainThread(async () =>
                        {
                            var responseToken = await fortiaServices.PostAsinc<TokenApiResponse>(new Object(), "/GetToken");

                            if (responseToken != null)
                            {
                                this.accountModel.tokenApi = responseToken;
                                this.accountModel.idTarjeta = this.accountModel.account.idTarjetaPrincipal;

                                //Agrega tarjetas
                                _views = new View[accountModel.Tarjetas.Count + 1];
                                _views[0] = new frmTarjeta(this.accountModel, this.accountModel.idTarjeta);

                                for (var i = 0; i < accountModel.Tarjetas.Count; i++)
                                {
                                    this.accountModel.idTarjeta = this.accountModel.Tarjetas[i].IdTarjeta;
                                    _views[i + 1] = new frmTarjeta(this.accountModel, this.accountModel.Tarjetas[i].IdTarjeta);
                                }

                                Carousel.ItemsSource = _views;
                                await GetInfoPrincipal();
                            }
                            else
                            {
                                await DisplayAlert("Tenemos problemas", "Los servicios no estan disponibles", "Continuar");
                                await Navigation.PushAsync(new frmLogin());
                            }
                        });

                        await Navigation.PopModalAsync(false);
                    }
                    else
                    {
                        await Navigation.PopModalAsync(false);
                        await DisplayAlert("Tenemos problemas", "Los servicios no estan disponibles", "Continuar");
                        await Navigation.PushAsync(new frmLogin());
                    }
                });
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }       
        }

        public async Task GetInfoPrincipal()
        {
            Device.BeginInvokeOnMainThread(async () =>
            {
                this.accountModel.idTarjeta = this.accountModel.account.idTarjetaPrincipal;
                var infoTarjeta = await fortiaServices.PostAsinc<FortiaClientModel>(accountModel, "/GetTarjeta");
                if (infoTarjeta != null)
                {
                    this.fortiaClientModelPrincipal = infoTarjeta;
                }
            });
        }

and this is my code in the class appDelegate in iOS

using CarouselView.FormsPlugin.iOS;
namespace FortiaApp.iOS
{
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            RoundedBoxViewRenderer.Init();
            AnimationViewRenderer.Init();
            CarouselViewRenderer.Init();
            LoadApplication(new App());
            return base.FinishedLaunching(app, options);
        }
    }
}

Answers

  • AndreiMisiukevich_AndreiMisiukevich_ USMember ✭✭✭✭✭

    Hi i suggest you to use this plugin https://github.com/AndreiMisiukevich/CardView
    Many people think it's more stable =)

  • DanielKondrashevichDanielKondrashevich Member ✭✭
    edited July 2018

    This sounds similar to my problem I ran into it yesterday. I would apply images to my CarouselView and nothing would show up (I'm using FFImageLoading for the images). After debugging for about 2 hours, I found out that what happens is the CarouselView doesn't work for me if I set it up inside:

    Device.BeginInvokeOnMainThread(async () =>
    {

    }

    When I take CarouselView code outside of this async method, everything works fine and loads correctly. I don't have a workaround yet but I believe this might be similar to the problem you're having.

    -Daniel.

  • DanielKondrashevichDanielKondrashevich Member ✭✭
    edited July 2018

    Your problem sounds similar to what I was debugging yesterday. For me, I realized that if I call any CarouselView code inside of this method, none of it would work:

    Device.BeginInvokeOnMainThread(async () => 
    {
    
    }
    

    I took the code out and my CarouselView started working again. It took me about 2-3 hours to figure this out. So frustrating.

    Edit: I found a work around if you need to call async code inside of the constructor.

            var task = Task.Run(async () => {
            //your async code here
            });
            return task.Result;
    

    I did this and now my CarouselView works correctly :smile:
    Edit2: I would like to mention that I call this code through a method from the constructor

Sign In or Register to comment.