【问题标题】:I have used FlowListView but it's not working properly in iOS?我使用了 FlowListView 但它在 iOS 中无法正常工作?
【发布时间】:2019-12-25 21:21:48
【问题描述】:

我为画廊视图创建了一个示例。为此,我使用了 flowlistview nuget。它在 Android 中运行良好,但在 iOS 中它在网格中显示一个奇怪的箭头。有什么想法吗?

UserPhotos.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:flv="clr-namespace:DLToolkit.Forms.Controls;assembly=DLToolkit.Forms.Controls.FlowListView"
    x:Class="MyApp.UserPhotos"
    Title="Photos">

    <ContentPage.Content>
        <StackLayout Padding="10" Margin="5">
            <flv:FlowListView 
                HasUnevenRows="True"
                FlowColumnCount="2"
                FlowItemTappedCommand="{Binding ItemTappedCommand}"
                SeparatorVisibility="Default"
                FlowItemsSource="{Binding userAlbumsList}">

                <flv:FlowListView.FlowColumnTemplate>
                    <DataTemplate>
                        <Frame x:Name="itemTemp"
                               Margin="5"
                               CornerRadius="5"
                               BackgroundColor="#5d6d20"
                               HorizontalOptions="FillAndExpand"
                               VerticalOptions="FillAndExpand">
                            <StackLayout Padding="0,8,0,8"
                                         VerticalOptions="Center"
                                         HorizontalOptions="Center">
                                <Image Aspect="AspectFit"
                                       HeightRequest="60"
                                       WidthRequest="60"
                                       Source="album.png"
                                       HorizontalOptions="CenterAndExpand"
                                       VerticalOptions="CenterAndExpand" />
                            </StackLayout>
                        </Frame>
                    </DataTemplate>
                </flv:FlowListView.FlowColumnTemplate>

            </flv:FlowListView>
        </StackLayout>
    </ContentPage.Content>

</ContentPage>

【问题讨论】:

    标签: c# xamarin xamarin.forms xamarin.ios


    【解决方案1】:

    您可以使用 CustomRenderer 来设置 iOS 中单元格的 Accessory。

    using MyApp.iOS;
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.iOS;
    
    [assembly: ExportRenderer(typeof(ViewCell), typeof(StandardViewCellRenderer))]
    namespace MyApp.iOS
    {
        public class StandardViewCellRenderer : ViewCellRenderer
        {
    
            public override UIKit.UITableViewCell GetCell(Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
            {
                var cell = base.GetCell(item, reusableCell, tv);
                switch (item.StyleId)
                {
                    case "none":
                        cell.SelectionStyle = UIKit.UITableViewCellSelectionStyle.None;
                        break;
                    case "checkmark":
                        cell.Accessory = UIKit.UITableViewCellAccessory.Checkmark;
                        break;
                    case "detail-button":
                        cell.Accessory = UIKit.UITableViewCellAccessory.DetailButton;
                        break;
                    case "detail-disclosure-button":
                        cell.Accessory = UIKit.UITableViewCellAccessory.DetailDisclosureButton;
                        break;
                    case "disclosure":
                    default:
                        cell.Accessory = UIKit.UITableViewCellAccessory.None;
                        break;
                }
                return cell;
    
    
            }
        }
    
    }
    

    【讨论】:

    • 检查我的更新答案,在您的示例中,默认设置cell.Accessory = UIKit.UITableViewCellAccessory.None;。
    • 你的iOS项目中有两个单元格渲染器,删除其中一个(Renderer文件夹中的CellRenderer)。并删除共享项目和iOS项目中的文件夹bin和obj,然后清理并重建它。
    • 现在我收到此错误 Method not found: void .ResourceLoadingQuery.set_Instance(object)
    • 确保共享项目和 iOS/Android 中的所有 Xamarin.forms 版本都是最新的。
    • 我使用了静态源,无论是否使用自定义渲染器都可以正常工作。我在 iOS 模拟器 13.2 上测试它。您可以下载并测试。github.com/luczha/FlowListView_Sample
    猜你喜欢
    • 2022-08-20
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 2022-01-23
    • 2016-04-11
    • 2021-06-14
    • 1970-01-01
    相关资源
    最近更新 更多