Радиус угла кругового изображения изменяется после прокрутки при первоначальной загрузке UITableView - Xamarin.iOS - PullRequest
0 голосов
/ 04 июня 2019

Я хочу сделать Cicicular UIImageView в моем UITableViewCell. Вот мой код

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
       RemoteSupportTableViewCell cell = (RemoteSupportTableViewCell)tableView.DequeueReusableCell(_cellIdentifier);
       RemotesupportAgentData item = _tableItems[indexPath.Row];

        cell.TextLabel.Text = (string)item.Attributes["Name"];
        cell.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
        UIImageView tempImageView = new UIImageView();
        tempImageView.SetImage(new NSUrl((string)item.Attributes["avatar"]), UIImage.FromBundle("contacts-32.png"));
        cell.ImageView.Image = MaxResizeImage(tempImageView.Image, 50, 50);
        CGRect imgvwFrame = cell.ImageView.Frame;
        imgvwFrame.Height = 50;
        imgvwFrame.Width = 50;
        cell.ImageView.Frame = imgvwFrame;
        cell.LayoutIfNeeded();

        return cell;
    }

В моей пользовательской ячейке

 public RemoteSupportTableViewCell(IntPtr handle)
        : base(handle)
    {
        SelectionStyle = UITableViewCellSelectionStyle.None;
        ImageView.ClipsToBounds = true;
        ImageView.Layer.MasksToBounds = true;
        ImageView.Layer.BorderColor = UIColor.Green.CGColor;
        ImageView.Layer.BorderWidth = (nfloat)2.0;
    }

    public override void Draw(CGRect rect)
    {
        base.Draw(rect);

        // Your will get the actual size in the event
        if (ImageView.Layer.CornerRadius == 0)
            ImageView.Layer.CornerRadius = ImageView.Frame.Width / 2;
    }

Когда я первоначально загружаю пользовательский интерфейс, я вижу свое изображение заполнителя в каждом изображении ячейки, и они представляют собой круги. Когда я прокручиваю табличное представление, оно начинает загружать изображения из URL и заменять изображение заполнителя. Но моя проблема в том, что при загрузке изображений из URL эти изображения не являются идеальными кругами. но если я вернусь к предыдущему ViewController и вернусь, то я увижу, что все загруженные по URL изображения помещены в идеальные круги.

Что происходит, когда я первоначально загружаю табличное представление? и как я могу преодолеть это? Спасибо

...